Adds the Supreme Court Database's coding to cases of the Supreme Court.
The Supreme Court Database (https://scdb.la.psu.edu) codes every case that the Supreme Court has decided since its 1946 term: the issue, the direction of the decision, what the court did with the decision below, which party won, and how each justice voted, among much else. Its online codebook explains each variable.
download gets the latest release from https://scdb.la.psu.edu/data/ and
keeps it outside of projects (in "scdb" in courtpy.utilities.data_folder()).
cases returns its table with a row for each case, and votes its table
with a row for each justice in each case. Both keep the database's names for
their columns (such as "issueArea" and "decisionDirection"), so the codebook
applies to them as it is.
code_scdb (an amos.Merger, which is added to the amos library as soon
as courtpy is imported) adds the database's columns to parsed cases of the
Supreme Court, with "scdb_" before their names. A case is matched by the
database's id for it, which CourtListener records ("scdb_id"), or else by
one of its citations:
import courtpy
cases = courtpy.parse("data/court_listener")
dataset = courtpy.code(cases, "code_scdb", parameters = {
"code_scdb": {"columns": "issueArea, decisionDirection, partyWinning"}})
Contents
CodeScdb: adds the Supreme Court Database's columns to each case.
cases: returns the database's table with a row for each case.
download: downloads the latest release of the database.
votes: returns the database's table with a row for each justice in each
case.
logger: the module's logger, which reports the files that are downloaded.
_CITATIONS: the columns of the database with the citations of a case, in
the order in which they are tried.
_SEPARATORS: pattern for the text between the citations of a case in a
table of parsed cases.
_SYMBOLS: pattern for everything in a citation other than letters and
digits, which _cite removes.
_cite: returns a citation the way that citations are compared.
_cited: returns the row of the database for each citation that one row
has.
_folder: returns the folder where the database is kept.
_read: returns a table from a table or a file, or one of the database's.
_release: finds the latest release of the database and its files.
CodeScdb(contents=None, name='', parameters=dict(), clerk=None)
dataclass
¶
Bases: Merger
Adds the Supreme Court Database's columns to each case.
Each case is matched to the database's row for it: the row with the case's id in the database ("scdb_id", which CourtListener records for cases of the Supreme Court), or else the row with one of the case's citations (such as "347 U.S. 483"). Rather than guess, a case whose citations are those of more than one row of the database (as short orders on one page of a reporter are) is not matched. A case that is not matched, such as a case of another court, gets missing values.
Like every merger of amos, it takes these parameters, never adds,
removes, or reorders rows, and records how many cases it matched in the
dataset's history:
| Parameter | Meaning |
|---|---|
source |
The database's table of cases: the path of its file (looked for in the current folder and then in the clerk's input folder), or a table. Without it, the latest release is used, which is downloaded unless it was before (see download). |
columns |
The columns of the database to add, by its names for them (such as "issueArea"). By default, they are all of them. |
prefix |
Text to put before the names of the added columns. It is "scdb_" unless another is set. |
indicator |
The name of a column to make that says whether each case was found in the database. |
on, other_on |
The columns of the cases and of the database with the database's id of each case. They are "scdb_id" and "caseId" unless others are set. |
citations |
The column of the cases with their citations. It is "citation" unless another is set. |
Needs "scdb_id" or "citation" (or the columns named by "on" and "citations").
implement(item, *, source=None, columns=None, prefix='scdb_', **kwargs)
¶
Adds the database's columns for each case of item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Dataset
|
the dataset of parsed cases. |
required |
source
|
Any
|
the database's table of cases, or the path of its file.
Defaults to |
None
|
columns
|
Sequence[str] | str | None
|
the columns of the database to add, as a list or as
text with commas between their names. Defaults to |
None
|
prefix
|
str | None
|
text to put before the names of the added columns. Defaults to "scdb_". |
'scdb_'
|
**kwargs
|
Any
|
other parameters of the mergers of |
{}
|
Raises:
| Type | Description |
|---|---|
KeyError
|
if the cases have neither the column of ids nor the column of citations, or one of "columns" is not in the database. |
ValueError
|
if an added column would have the name of a column of the cases. |
Returns:
| Type | Description |
|---|---|
Dataset
|
The dataset, with the new columns. |
Source code in src/courtpy/scdb.py
match(data, other, *, on='scdb_id', other_on='caseId', citations='citation', **kwargs)
¶
Returns the row of the database for each case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
the parsed cases. |
required |
other
|
DataFrame
|
the database's table of cases. |
required |
on
|
str
|
the column of |
'scdb_id'
|
other_on
|
str
|
the column of |
'caseId'
|
citations
|
str
|
the column of |
'citation'
|
**kwargs
|
Any
|
not used. |
{}
|
Raises:
| Type | Description |
|---|---|
KeyError
|
if |
Returns:
| Type | Description |
|---|---|
Any
|
The position of the matching row of |
Source code in src/courtpy/scdb.py
read(source, **kwargs)
¶
Returns the database's table of cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Any
|
the path of the database's file (a CSV file, or a zip archive of one, as it is downloaded), or a table. |
required |
**kwargs
|
Any
|
parameters for loading any other kind of source (see
|
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table. |
Source code in src/courtpy/scdb.py
cases(source=None)
¶
Returns the Supreme Court Database's table with a row for each case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataFrame | Path | str | None
|
the database's case centered file that is organized by
citation (a CSV file, or the zip archive of one that
https://scdb.la.psu.edu/data/ offers), as a path or a table.
Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table, with the database's names for its columns: "caseId" (such as "1946-001"), "usCite", "term", "caseName", "issueArea", "decisionDirection", "partyWinning", "majVotes", "minVotes", and the rest that its codebook explains. |
Source code in src/courtpy/scdb.py
download(folder=None, *, kinds=None, overwrite=False, session=None)
¶
Downloads the latest release of the Supreme Court Database.
The files are those of the modern database (the terms since 1946) that are organized by citation, as zip archives of CSV files. They need no account:
| Kind | File |
|---|---|
cases |
The case centered data: a row for each case (less than a megabyte). |
votes |
The justice centered data: a row for each justice in each case (about 2 megabytes). |
A file is saved with the name of its release (such as "SCDB_2026_01_caseCentered_Citation.csv.zip"), so the release that a study used is in the dataset's history. The database's page lists its releases, and the page of the latest one links to its files, so they are found by those links.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder
|
Path | str | None
|
the folder to save them in. Defaults to |
None
|
kinds
|
Sequence[str] | str | None
|
the files to download: "cases", "votes", or both. Defaults to
|
None
|
overwrite
|
bool
|
whether to look for the latest release even if the folder
has a file of an earlier one (or of the same one). A new release
comes out each year. Defaults to |
False
|
session
|
Any
|
an object with a |
None
|
Raises:
| Type | Description |
|---|---|
HTTPError
|
if a page or a file cannot be downloaded. |
ValueError
|
if one of |
Returns:
| Type | Description |
|---|---|
dict[str, Path]
|
The path of each file, by its kind. If the folder has the files of more than one release, they are those of the latest. |
Source code in src/courtpy/scdb.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
votes(source=None)
¶
Returns the database's table with a row for each justice in each case.
The table is for studying how the justices vote. The Martin-Quinn score
of each justice in each term (see courtpy.politics.justices) can be
added to it with the merge_keys technique of amos, by "term" and
"justice".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataFrame | Path | str | None
|
the database's justice centered file that is organized by
citation (a CSV file, or the zip archive of one that
https://scdb.la.psu.edu/data/ offers), as a path or a table.
Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The table, with the columns of |