Coverage for src/courtpy/core/options.py: 100%
32 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-22 15:51 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-22 15:51 +0000
1"""Default settings for courtpy.
3These are module-level constants so that a project built on `courtpy` can
4change them before they are used (for example,
5`courtpy.options._MIN_INTERVAL = 2.0` to slow down requests to the
6CourtListener API). Tables of the federal courts and the presidents are in
7"instructions/federal" (see `courtpy.courts` and `courtpy.politics`).
9Contents:
10 _API_URL: base address of the CourtListener REST API (version 4).
11 _BULK_PREFIX: folder of the CourtListener bulk data in its bucket.
12 _BULK_URL: address of the public bucket with CourtListener's bulk data.
13 _CHUNK_SIZE: number of saved cases given to a process at a time when
14 parsing with several processes.
15 _COURT_GROUPS: names for groups of CourtListener court ids.
16 _DATA_SUBFOLDER: the folder of the `amos` workspace's data folder that
17 holds courtpy's downloads.
18 _DEFAULT_CODERS: techniques that code variables after cases are parsed.
19 _DEFAULT_JURISDICTION: rulebooks used when none are named.
20 _REQUIRED_RULEBOOKS: rulebooks applied to every case, after its
21 source's header rulebook and before those that are named.
22 _DOCKET_SKIPPED: fields of a CourtListener docket that are not kept with
23 a saved case.
24 _ENV_API_KEY: environment variable that can hold the API key.
25 _ENV_CONFIG: environment variable that can name the configuration folder.
26 _ENV_DATA: environment variable that can name the data folder.
27 _IDB_CIRCUITS: the Federal Judicial Center's Integrated Database's code
28 for the circuit of each CourtListener court of appeals.
29 _IDB_FIRST_YEAR: the first year of the Integrated Database's records of
30 appeals.
31 _JUDGE_GRACE: years after a judge leaves a court in which an opinion may
32 still name the judge.
33 _KEYRING_SERVICE: name under which the API key is kept in a keyring.
34 _KEYRING_USERNAME: user name under which the API key is kept.
35 _LARGE_SECTIONS: sections of text that are not kept in a case table
36 unless asked.
37 _MAX_WAIT: most seconds to wait when the API asks for a pause.
38 _MIN_INTERVAL: fewest seconds between requests to the API.
39 _OPINION_FIELDS: opinion fields requested from the CourtListener API.
40 _PDF_DELAY: seconds between requests for opinions' PDFs to one court's
41 website.
42 _SCDB_FILES: the part of the name of each file of the Supreme Court
43 Database that courtpy uses, by what `courtpy.scdb` calls each.
44 _SCDB_LINK: the words of the links to those files on the page of a
45 release of the Supreme Court Database.
46 _SCDB_PAGE: address of the page that links to the releases of the
47 Supreme Court Database.
48 _SCDB_RELEASE: pattern for the address of the page of a release of the
49 modern Supreme Court Database.
50 _SOURCES: sources of court opinions that courtpy can read.
51 _TEXT_FIELDS: CourtListener fields with the text of an opinion, in the
52 order they are preferred.
53 _TIMEOUT: seconds to wait for a response from a server.
54 _USER_AGENT: how courtpy identifies itself to servers.
56"""
58from __future__ import annotations
60_API_URL: str = 'https://www.courtlistener.com/api/rest/v4/'
61_BULK_PREFIX: str = 'bulk-data/'
62_BULK_URL: str = (
63 'https://com-courtlistener-storage.s3-us-west-2.amazonaws.com/')
64# Each process is given this many cases at a time. One task per case
65# overwhelmed the pool with about 900,000 cases, and chunks also let progress
66# be logged.
67_CHUNK_SIZE: int = 1000
68# Names that can be used in place of a list of CourtListener court ids.
69_COURT_GROUPS: dict[str, tuple[str, ...]] = {
70 'federal_appellate': (
71 'ca1', 'ca2', 'ca3', 'ca4', 'ca5', 'ca6', 'ca7', 'ca8', 'ca9', 'ca10',
72 'ca11', 'cadc', 'cafc'),
73 'federal_geographic_circuits': (
74 'ca1', 'ca2', 'ca3', 'ca4', 'ca5', 'ca6', 'ca7', 'ca8', 'ca9', 'ca10',
75 'ca11', 'cadc'),
76 'scotus': ('scotus',)}
77# The folder of the `amos` workspace's data folder where courtpy keeps the
78# downloads that every project shares (see `utilities.data_folder`).
79_DATA_SUBFOLDER: str = 'courts'
80# Coders are run in this order because each uses columns made by the ones
81# before it.
82_DEFAULT_CODERS: tuple[str, ...] = (
83 'code_parties', 'code_case_type', 'code_outcome')
84_DEFAULT_JURISDICTION: str = 'federal'
85# Each source's header rulebook (its `header`, such as "lexis_nexis_header") is
86# applied before these, since the coders use the parties' roles, the court,
87# the judges, and the disposition that it finds.
88_REQUIRED_RULEBOOKS: tuple[str, ...] = ('general',)
89# Every other field of a docket is saved with its case. These are dates the
90# record changed, where CourtListener and the Internet Archive store their
91# copies, and how often the docket was viewed.
92_DOCKET_SKIPPED: frozenset[str] = frozenset({
93 'date_created', 'date_modified', 'date_last_index', 'filepath_local',
94 'filepath_ia', 'filepath_ia_json', 'ia_upload_failure_count',
95 'ia_needs_upload', 'ia_date_first_change', 'view_count'})
96_ENV_API_KEY: str = 'COURTLISTENER_API_KEY'
97_ENV_CONFIG: str = 'COURTPY_CONFIG_DIR'
98_ENV_DATA: str = 'COURTPY_DATA_DIR'
99# The Integrated Database numbers the regional circuits as the courts do, and
100# the D.C. Circuit 0. The Federal Circuit ("cafc") is not in it.
101_IDB_CIRCUITS: dict[str, str] = {
102 'cadc': '0', 'ca1': '1', 'ca2': '2', 'ca3': '3', 'ca4': '4', 'ca5': '5',
103 'ca6': '6', 'ca7': '7', 'ca8': '8', 'ca9': '9', 'ca10': '10',
104 'ca11': '11'}
105# The Federal Judicial Center's files of appeals begin with its 2008 fiscal
106# (statistical) year, which ended on September 30, 2008.
107_IDB_FIRST_YEAR: int = 2008
108# An opinion can be issued after one of its judges has died, retired, or
109# moved to another court, so a name still matches a judge for this many
110# years after the judge's service on a court ended.
111_JUDGE_GRACE: int = 2
112_KEYRING_SERVICE: str = 'courtpy'
113_KEYRING_USERNAME: str = 'courtlistener'
114# Sections of text so long that they are only kept in a case table if
115# "keep_text" is true. The opinion's words are still counted and searched.
116_LARGE_SECTIONS: tuple[str, ...] = (
117 'text', 'header', 'opinion', 'opinion_lines', 'pdf_header')
118# A free CourtListener account allows 5 requests a minute, 50 an hour, and
119# 125 a day (as of 2026). Waiting up to an hour rides out the first two
120# limits. A longer pause (the daily limit) stops the download, which can be
121# resumed later.
122_MAX_WAIT: float = 3600.0
123_MIN_INTERVAL: float = 1.0
124# Courts' websites have no stated limits, so requests for their PDFs are
125# spaced to be polite.
126_PDF_DELAY: float = 0.5
127_OPINION_FIELDS: tuple[str, ...] = (
128 'id', 'cluster_id', 'type', 'author_id', 'author_str', 'per_curiam',
129 'joined_by_str', 'ordering_key', 'download_url', 'html_with_citations',
130 'plain_text')
131# The Supreme Court Database's files that are organized by citation (one row
132# for each case, or for each justice in each case), which are named such as
133# "SCDB_2026_01_caseCentered_Citation.csv.zip". The page of a release links
134# to the case centered file before the justice centered one, with the same
135# words for both.
136_SCDB_FILES: dict[str, str] = {
137 'cases': 'caseCentered_Citation',
138 'votes': 'justiceCentered_Citation'}
139_SCDB_LINK: str = 'CSV Organized by Supreme Court Citation'
140_SCDB_PAGE: str = 'https://scdb.la.psu.edu/data/'
141_SCDB_RELEASE: str = r'/data/(\d{4})-release-(\d+)/?$'
142_SOURCES: tuple[str, ...] = ('courtlistener', 'lexis_nexis')
143# CourtListener recommends "html_with_citations" as the most reliable text.
144_TEXT_FIELDS: tuple[str, ...] = (
145 'html_with_citations', 'html_columbia', 'html_lawbox', 'xml_harvard',
146 'html_anon_2020', 'html', 'plain_text')
147_TIMEOUT: float = 60.0
148_USER_AGENT: str = 'courtpy (https://github.com/WithPrecedent/courtpy)'