Download Client

class legislice.download.Client(api_token='', api_root='https://authorityspoke.com/api/v1', update_coverage_from_api=True)

Downloader for legislative text.

citations_to(target)

Load an InboundReference object for each provision citing the target USLM provision URI.

Parameters

target (Union[str, Enactment, CrossReference]) – a string URI for the cited node, an Enactment at the cited node, or a CrossReference to the cited node

Return type

List[InboundReference]

Returns

a list of InboundReferences to the cited node

fetch(query, date='')

Download legislative provision from string identifier or cross-reference.

Parameters
  • query (Union[str, CitingProvisionLocation, CrossReference, InboundReference]) – A cross-reference to the desired legislative provision, or a path to the desired legislation section using the United States Legislation Markup tree-like citation format.

  • date (Union[date, str]) – The date of the desired version of the provision to be downloaded. This is not needed if a CrossReference passed to the query param specifies a date. If no date is provided, the API will use the most recent date.

Return type

RawEnactment

fetch_citations_to(target)

Query API for citations to a given target node, withoout loading them as InboundCitations.

Parameters

target (Union[str, Enactment, CrossReference]) – a string URI for the cited node, an Enactment at the cited node, or a CrossReference to the cited node

Return type

List[FetchedCitationDict]

Returns

a list of dicts representing citations to the cited node

fetch_citing_provision(query)

Download legislative provision as Enactment from CitingProvisionLocation.

CitingProvisionLocations are found in the locations attribute of the InboundReference objects obtained when using the citations_to method.

Return type

RawEnactment

fetch_cross_reference(query, date='')

Download legislative provision from cross-reference.

Parameters
  • query (CrossReference) – A cross-reference to the desired legislative provision. Found by calling the cross_references() method on an Enactment that contains one or more citations to other provisions.

  • date (Union[date, str]) – The date of the desired version of the provision to be downloaded. This is not needed if the CrossReference passed to the query param specifies a date. If no date is provided, the API will use the most recent date.

Return type

RawEnactment

fetch_db_coverage(code_uri)

Document date range of provisions of a code of laws available in API database.

Return type

PublicationCoverage

fetch_inbound_reference(query)

Download legislative provision from InboundReference.

Parameters

query (InboundReference) – An InboundReference identifying a provision containing a citation.

Return type

RawEnactment

Returns

An Enactment representing the provision containing the citation (not the cited provision).

If the InboundReference has been enacted more than once, the latest one will be chosen.

fetch_uri(query, date='')

Fetch data about legislation at specified path and date from Client’s assigned API root.

Parameters
  • query (str) – A path to the desired legislation section using the United States Legislation Markup tree-like citation format. Examples: “/us/const/amendment/IV”, “/us/usc/t17/s103”

  • date (Union[date, str]) – A date when the desired version of the legislation was in effect. This does not need to be the “effective date” or the first date when the version was in effect. However, if you select a date when two versions of the provision were in effect at the same time, you will be given the version that became effective later.

Return type

RawEnactment

get_db_coverage(uri)

Add data about the API’s coverage date range to the Enactment to be loaded.

As a side effect, changes the Client’s “coverage” attribute.

Parameters

uri (str) – identifier for the Enactment to be created

Return type

str

Returns

identifier for the Code of the Enactment to be created

read(query, date='')

Fetch data from Client’s assigned API root and builds Enactment or LinkedEnactment.

All text is selected by default.

Parameters
  • path – A path to the desired legislation section using the United States Legislation Markup tree-like citation format. Examples: “/us/const/amendment/IV”, “/us/usc/t17/s103”

  • date (Union[date, str]) – A date when the desired version of the legislation was in effect. This does not need to be the “effective date” or the first date when the version was in effect. However, if you select a date when two versions of the provision were in effect at the same time, you will be given the version that became effective later.

Return type

Enactment

read_from_json(data, use_text_expansion=True)

Create a new Enactment object using imported JSON data.

If fields are missing from the JSON, they will be fetched using the API key.

Return type

Enactment

read_passage_from_json(data)

Create a new EnactmentPassage object using imported JSON data.

If fields are missing from the JSON, they will be fetched using the API key.

Return type

EnactmentPassage

update_data_from_api_if_needed(data)

Update data from API with data from API coverage.

Parameters

data (RawEnactment) – a dict representing the data from the API

Return type

RawEnactment

Returns

a dict representing the data from the API with updated data from API coverage

update_enactment_from_api(data)

Use API to fill in missing fields in a dict representing an Enactment.

Useful when the dict has missing data because it was created by a user.

Return type

RawEnactment

update_entries_in_enactment_index(enactment_index)

Fill in missing fields in every entry in an EnactmentIndex.

Return type

Mapping[str, RawEnactmentPassage]

uri_from_query(target)

Get a URI for the target object.

Return type

str

url_from_enactment_path(path, date='')

Generate URL for API call for specified USLM path and date.

Return type

str

legislice.download.normalize_path(path)

Make sure path starts but does not end with a slash.

Return type

str