|
| 1 | +Civis API Python Client |
| 2 | +======================= |
| 3 | + |
| 4 | +Introduction |
| 5 | +------------ |
| 6 | + |
| 7 | +The Civis API Python client is a Python package that helps analysts and |
| 8 | +developers interact with the Civis Platform. The package includes a set of |
| 9 | +tools around common workflows as well as a convenient interface to make |
| 10 | +requests directly to the Civis API. See the |
| 11 | +`full documentation <https://civis-python.readthedocs.io>`_ for more details. |
| 12 | + |
| 13 | + |
| 14 | +Installation |
| 15 | +------------ |
| 16 | + |
| 17 | +1. Get a Civis API key `(instructions) <https://civis.zendesk.com/hc/en-us/articles/216341583-Generating-an-API-Key>`_. |
| 18 | +2. Add a ``CIVIS_API_KEY`` environment variable. |
| 19 | +3. You can add the following to ``.bash_profile`` for bash:: |
| 20 | + |
| 21 | + export CIVIS_API_KEY="alphaNumericApiK3y" |
| 22 | + |
| 23 | +4. Source your ``.bash_profile`` |
| 24 | +5. Install the package:: |
| 25 | + |
| 26 | + pip install civis |
| 27 | + |
| 28 | +6. Optionally, install ``pandas``, ``pubnub``, and ``requests-toolbelt`` to enable some functionality in ``civis-python``:: |
| 29 | + |
| 30 | + pip install pandas |
| 31 | + pip install pubnub |
| 32 | + pip install requests-toolbelt |
| 33 | + |
| 34 | + Installation of ``pandas`` will allow some functions to return ``DataFrame`` outputs. |
| 35 | + Installation of ``pubnub`` will improve performance in all functions which |
| 36 | + wait for a Civis Platform job to complete. |
| 37 | + Installation of ``requests-toolbelt`` will allow streaming file uploads to |
| 38 | + Civis via ``civis.io.file_to_civis``. |
| 39 | + |
| 40 | +Usage |
| 41 | +----- |
| 42 | + |
| 43 | +``civis-python`` includes a number of wrappers around the Civis API for |
| 44 | +common workflows. |
| 45 | + |
| 46 | +.. code-block:: python |
| 47 | +
|
| 48 | + import civis |
| 49 | + df = civis.io.read_civis(table="my_schema.my_table", |
| 50 | + database="database", |
| 51 | + use_pandas=True) |
| 52 | +
|
| 53 | +The Civis API may also be directly accessed via the ``APIClient`` class. |
| 54 | + |
| 55 | +.. code-block:: python |
| 56 | +
|
| 57 | + import civis |
| 58 | + client = civis.APIClient() |
| 59 | + database = client.databases.list() |
| 60 | +
|
| 61 | +See the `full documentation <https://civis-python.readthedocs.io>`_ for a more |
| 62 | +complete user guide. |
| 63 | + |
| 64 | +Retries |
| 65 | +~~~~~~~ |
| 66 | + |
| 67 | +The API client will automatically retry for certain API error responses. |
| 68 | + |
| 69 | +If the error is one of [413, 429, 503] and the API client is told how long it needs |
| 70 | +to wait before it's safe to retry (this is always the case with 429s, which are |
| 71 | +rate limit errors), then the client will wait the specified amount of time |
| 72 | +before retrying the request. |
| 73 | + |
| 74 | +If the error is one of [429, 502, 503, 504] and the request is not a ``patch*`` or ``post*`` |
| 75 | +method, then the API client will retry the request several times, with a delay, |
| 76 | +to see if it will succeed. |
| 77 | + |
| 78 | +Build Documentation Locally |
| 79 | +--------------------------- |
| 80 | + |
| 81 | +To build the API documentation locally:: |
| 82 | + |
| 83 | + cd docs |
| 84 | + make html |
| 85 | + |
| 86 | +Then open ``docs/build/html/index.html``. |
| 87 | + |
| 88 | +Note that this will use your API key in the ``CIVIS_API_KEY`` environment |
| 89 | +variable so it will generate documentation for all the endpoints that you have access to. |
| 90 | + |
| 91 | +Contributing |
| 92 | +------------ |
| 93 | + |
| 94 | +See ``CONTRIBUTING.md`` for information about contributing to this project. |
| 95 | + |
| 96 | + |
| 97 | +License |
| 98 | +------- |
| 99 | + |
| 100 | +BSD-3 |
| 101 | + |
| 102 | +See ``LICENSE.md`` for details. |
0 commit comments