Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.6 KB

client.rst

File metadata and controls

46 lines (35 loc) · 1.6 KB

API Client

~civis.APIClient is a class for handling requests to the Civis API. An instantiated ~civis.APIClient contains a set of resources (listed below) where each resource is an object with methods. By convention, an instantiated ~civis.APIClient object is named client and API requests are made with the following syntax:

client = civis.APIClient()
response = client.resource.method(params)

The methods on ~civis.APIClient are created dynamically at runtime by parsing an python:collections.OrderedDict representation of the Civis API specification. By default, this specification is downloaded from the /endpoints endpoint the first time ~civis.APIClient is instantiated (and cached in memory for the remainder of the program's run). In some circumstances, it may be useful to use a local cache of the API specification rather than downloading the spec. This can be done by passing the specification to the client through the parameter local_api_spec as either the python:collections.OrderedDict or a filename where the specification has been saved.

api_key = os.environ['CIVIS_API_KEY']
spec = civis.resources.get_api_spec(api_key)

# From OrderedDict
client = civis.APIClient(local_api_spec=spec)

# From file
with open('local_api_spec.json', 'w') as f:
    json.dump(spec, f)
client = civis.APIClient(local_api_spec='local_api_spec.json')

civis

civis.APIClient

responses api_resources