# 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](/sdks/python-sdk/python-sdk-tutorial-news-application.md) 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="/files/BjxT2jgDmxw8BOZIAZGt" 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="/files/8rlumS7JLsbvVaEDk4YH" 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="/files/6bJqWlBvERFXJWoucrvV" alt=""><figcaption></figcaption></figure>

Additionally, you can generate a `NEURELO_API_KEY` by [creating a new API Key](/environments/api-keys.md) 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)](/sdks/python-sdk/python-sdk-tutorial-news-application.md)
* [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 [Project Examples](/project-examples.md#projects-built-using-neurelo-sdks)&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.neurelo.com/sdks/python-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
