MCPcopy Create free account
hub / github.com/LibraryOfCongress/api.congress.gov / CDGClient

Class CDGClient

api_client/python/cdg_client.py:35–61  ·  view source on GitHub ↗

A sample client to interface with Congress.gov.

Source from the content-addressed store, hash-verified

33
34
35class CDGClient:
36 """ A sample client to interface with Congress.gov. """
37
38 def __init__(
39 self,
40 api_key,
41 api_version=API_VERSION,
42 response_format=RESPONSE_FORMAT,
43 raise_on_error=True,
44 ):
45 self.base_url = urljoin(ROOT_URL, api_version) + "/"
46 self._session = requests.Session()
47
48 # do not use url parameters, even if offered, use headers
49 self._session.params = {"format": response_format}
50 self._session.headers.update({"x-api-key": api_key})
51
52 if raise_on_error:
53 self._session.hooks = {
54 "response": lambda r, *args, **kwargs: r.raise_for_status()
55 }
56
57 def __getattr__(self, method_name):
58 """Find the session method dynamically and cache for later."""
59 method = _MethodWrapper(self, method_name)
60 self.__dict__[method_name] = method
61 return method

Callers 1

bill_example.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected