# Getting started

## Installation

The easiest way to get started with the redivis-python client library is via a [Redivis notebook](https://docs.redivis.com/reference/projects/notebook-nodes), which comes with the latest version of this library pre-installed. Additionally, authentication is automatically handled within the Redivis notebook environment.

{% hint style="success" %}
Consult the [Python notebooks documentation](https://docs.redivis.com/reference/projects/notebook-nodes/python-notebooks) for examples of common workflows when reading data from Redivis.&#x20;
{% endhint %}

If you'd like to use the client in another environment, you can install the redivis library [from PyPI](https://pypi.org/project/redivis/). Use pip, or your python package manager of choice, to install:

```bash
pip install --upgrade redivis
```

## Example usage

```python
import redivis

organization = redivis.organization("demo")
dataset = organization.dataset("cms_2014_medicare_data")
table = dataset.table("home_health_agencies")

df = table.to_pandas_dataframe()
```

When referencing datasets, workflows, and tables on Redivis, you should be familiar with the [resource reference syntax](https://apidocs.redivis.com/referencing-resources).

## Authentication

### Within a Redivis notebook (automatic)

If you are using the redivis-python library within a notebook on Redivis, you'll automatically be authenticated and have access to any data within your workflow.

### From another environment (OAuth)

If you are running the redivis-python library on another system (e.g., your laptop, Google Colab, or a shared compute cluster), you will be prompted to authenticate with your Redivis account the first time you run a command. Follow the printed instructions to authorize the python client to communicate with the Redivis API.

### From a long-running service (API Token)

If you are developing a service that regularly interacts with Redivis without human intervention – for example, a recurring job that runs a data ingest pipeline – you can [generate an API token](https://docs.redivis.com/api/rest-api/authorization#api-token) to allow the service to act on your behalf.

{% hint style="danger" %}
API Tokens must be treated with extreme care, as a leaked token can allow somebody else to act on your behalf. These tokens should be treated like passwords, and never committed to source control or stored as strings in the text of your code.

API Tokens are only required for long-running services that operate without a human actor. If you are engaging with the Redivis API interactively, you should instead use the simpler and more secure OAuth flow mentioned above.
{% endhint %}

This API token must then be set as the `REDIVIS_API_TOKEN` [environment variable](https://docs.redivis.com/api/client-libraries/reference#environment-variables) before running your python script. You can set the variable for your current session by running the following in your terminal:

```bash
export REDIVIS_API_TOKEN=YOUR_TOKEN
```

## Learn more

{% content-ref url="reference" %}
[reference](https://docs.redivis.com/api/client-libraries/redivis-python/reference)
{% endcontent-ref %}

{% content-ref url="examples" %}
[examples](https://docs.redivis.com/api/client-libraries/redivis-python/examples)
{% endcontent-ref %}
