# Python SDK

## Overview

The generated Neurelo Python SDK provides easy access to your Neurelo APIs for Python applications.

{% hint style="info" %}
Refer to this guide [python-sdk-tutorial-news-application](https://docs.neurelo.com/sdks/python-sdk/python-sdk-tutorial-news-application "mention") for a detailed tutorial on downloading, installing, and using the Python SDKs with FastAPI.
{% endhint %}

## Installation

Download the Custom Python SDK for your Project from the APIs page under the Neurelo environment that you want to interact with.

<figure><img src="https://3406482452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvzFLT4zSSU6J1uzbt5OF%2Fuploads%2FnJdpdlyBeChk2kq2Au9B%2FDownload_Python_SDK.png?alt=media" alt=""><figcaption></figcaption></figure>

A gzip compressed tar archive (`.tgz`) SDK file should be downloaded. First, **uncompress** this file to get the underlying folder. Doing so, you are likely to see a directory as follows:

<figure><img src="https://3406482452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvzFLT4zSSU6J1uzbt5OF%2Fuploads%2FYFaTd5fZsMWdlZJApqJi%2Fimage.png?alt=media&#x26;token=56fcefe4-67f6-45c7-b05c-ebe4f31db42f" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The downloaded SDK file will be named - `neurelo-sdk-python-cmt_xxxxxx.tgz` (where `xxxxxx` are the last 6 digits of the definition commit applied to the environment)
{% endhint %}

To install the necessary dependencies for this SDK, we will use the `requirements.txt` as follows:

```bash
$ python3 -m pip install -r ./requirements.txt
```

{% hint style="warning" %}
If you have used Neurelo SDK’s in the past, to ensure that the **older version** of `neurelo` package is **uninstalled**, do a `python3 -m pip uninstall neurelo` and rerun your `requirements.txt` command from above.
{% endhint %}

## Usage

### API Usage

Basic usage requires instantiating both a `Configuration` and an `ApiClient` class:

```python
from neurelo.configuration import Configuration
from neurelo.api_client import ApiClient

configuration = Configuration(
	host=NEURELO_API_HOST,
	api_key={'ApiKey': NEURELO_API_KEY}
)

api_client = ApiClient(configuration=configuration)
```

Each object defined in your Neurelo data definition has a class that can be instantiated by passing the `ApiClient` instance into the constructor of the object's class. For example, if your data definition contains a 'User' object, you can instantiate the User class by passing the `ApiClient` instance into its constructor as shown below:

```python
from neurelo.api.user_api import UserApi

user_api = UserApi(api_client)
```

To obtain the `NEURELO_API_HOST`, simply copy the host name mentioned in the Environments tab.

<figure><img src="https://3406482452-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvzFLT4zSSU6J1uzbt5OF%2Fuploads%2FGf1XkFATvxZYUQ1qQWM5%2Fimage.png?alt=media&#x26;token=3c7f618a-b5a3-41b6-9f88-57825b1c8776" alt=""><figcaption></figcaption></figure>

Additionally, you can generate a `NEURELO_API_KEY` by [creating a new API Key](https://docs.neurelo.com/environments/api-keys) from the **“API Keys”** tab. You can export these values using a command similar to the following in our terminal:

```bash
$ export NEURELO_API_KEY="<YOUR-API-KEY>"
$ export NEURELO_API_HOST="<HOST-NAME>"
```

When calling operations with body, the body is encapsulated within specific classes. To use it, create an instance of the respective class and use the parameter values, as shown below:

```python
from neurelo import models

payload = models.UserCreateInput(
  email=email,
  fullname=fullname,
  password=password,
)

user = user_api.create_one_user(payload)
```

Similarly, when calling **operations with parameters** (for example, fetching all user info containing a email as `XYZ`), the parameters are also encapsulated within specific classes. To use these parameters, we create an instance of the respective class and use it as the parameter value, as shown below.

```python
filtered = models.UserWhereInput.from_dict({"email": {"equals": template_email}})
users = user_api.find_user(filter=filtered)
```

**It is important to use our** **`models`** **submodule** **to create these parameters**. The resulting parameter expression, like `{"email": {"equals": template_email}}`, is standard with our **REST API**. More information on this can be found in our [Neurelo API Reference (REST) guide](https://docs.neurelo.com/neurelo-api-reference-rest).

{% hint style="warning" %}
Although you can directly make API calls with parameters using the object API class as follows: `user_api.find_user(filter=<filter-condition>)`, we do not recommend this approach. Instead, use the **models** submodule to create the parameters.
{% endhint %}

Type hints are available for all parameters, for all operations to aid in understanding which class is should be used with each parameter.

## Example Applications

The following applications are provided to demonstrate how to use Neurelo, and Neurelo’s generated Python SDK.

* [Python SDK Tutorial (News Application)](https://docs.neurelo.com/sdks/python-sdk/python-sdk-tutorial-news-application)
* [Python FastAPI + Jinja FullStack App](https://github.com/neurelo-public/neurelo-sdk-examples/tree/main/python/fastapi-jinja)

To review more examples of applications built using Neurelo's SDK, please visit [#projects-built-using-neurelo-sdks](https://docs.neurelo.com/project-examples#projects-built-using-neurelo-sdks "mention")&#x20;
