Skip to content

Courts registry

The static registry of every supported court and the helpers for resolving them by code, name, eCourts state code, or CNR prefix.

courts

Registry of Indian courts with eCourts identifiers.

State codes are from the HC Services portal (hcservices.ecourts.gov.in). These were verified by probing the fillHCBench endpoint.

Judgment codes are from the judgments.ecourts.gov.in portal, verified against vanga/indian-high-court-judgments court-codes.json.

ALL_COURTS module-attribute

ALL_COURTS: list[Court] = [SUPREME_COURT] + HIGH_COURTS

SUPREME_COURT module-attribute

SUPREME_COURT = Court(
    name="Supreme Court of India",
    code="sci",
    state_code="0",
    court_type=CourtType.SUPREME_COURT,
)

get_court

get_court(code: str) -> Court | None

Look up a court by its code (e.g. 'delhi', 'bombay-nagpur', 'sci').

Source code in src/bharat_courts/courts.py
def get_court(code: str) -> Court | None:
    """Look up a court by its code (e.g. 'delhi', 'bombay-nagpur', 'sci')."""
    return _BY_CODE.get(code.lower())

get_court_by_name

get_court_by_name(name: str) -> Court | None

Look up a court by name (case-insensitive).

Source code in src/bharat_courts/courts.py
def get_court_by_name(name: str) -> Court | None:
    """Look up a court by name (case-insensitive)."""
    return _BY_NAME.get(name.lower())

get_court_by_state_code

get_court_by_state_code(state_code: str) -> Court | None

Look up the principal court for a state code (bench variants excluded).

The archive bucket partitions HCs by state code; this resolves the canonical court for that partition. Returns None for state_code "0" (Supreme Court — use SUPREME_COURT directly).

Source code in src/bharat_courts/courts.py
def get_court_by_state_code(state_code: str) -> Court | None:
    """Look up the principal court for a state code (bench variants excluded).

    The archive bucket partitions HCs by state code; this resolves the
    canonical court for that partition. Returns None for state_code "0"
    (Supreme Court — use ``SUPREME_COURT`` directly).
    """
    return _BY_STATE_CODE.get(str(state_code))

infer_court_from_cnr

infer_court_from_cnr(cnr: str | None) -> Court | None

Identify the court that issued a CNR from its 4-letter prefix.

The CNR's prefix is deterministic per court (verified against the AWS archive for all 25 HCs + SCI). Returns None for unknown / malformed inputs — never raises.

Useful for routing archive queries: passing the CNR alone scans every HC partition (slow), but infer_court_from_cnr(cnr) lets the caller narrow to one bucket / partition first.

Source code in src/bharat_courts/courts.py
def infer_court_from_cnr(cnr: str | None) -> Court | None:
    """Identify the court that issued a CNR from its 4-letter prefix.

    The CNR's prefix is deterministic per court (verified against the AWS
    archive for all 25 HCs + SCI). Returns ``None`` for unknown / malformed
    inputs — never raises.

    Useful for routing archive queries: passing the CNR alone scans every
    HC partition (slow), but ``infer_court_from_cnr(cnr)`` lets the caller
    narrow to one bucket / partition first.
    """
    if not cnr or len(cnr) < 4:
        return None
    code = _CNR_PREFIX_TO_COURT_CODE.get(cnr[:4].upper())
    return get_court(code) if code else None

list_all_courts

list_all_courts() -> list[Court]

Return all courts including Supreme Court.

Source code in src/bharat_courts/courts.py
def list_all_courts() -> list[Court]:
    """Return all courts including Supreme Court."""
    return list(ALL_COURTS)

list_high_courts

list_high_courts() -> list[Court]

Return all High Courts.

Source code in src/bharat_courts/courts.py
def list_high_courts() -> list[Court]:
    """Return all High Courts."""
    return list(HIGH_COURTS)