> For the complete documentation index, see [llms.txt](https://docs.akkio.com/akkio-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.akkio.com/akkio-docs/endpoints-and-schemas/additional-libraries/python.md).

# Python Library

## API Keys

As noted in the code samples below, you must get your API keys and copy them into your API code. Those can be found under the [team settings page](https://app.akkio.com/team-settings) at the bottom of the Akkio app.

<figure><img src="/files/FDFQcGjJAwuold5PD04o" alt=""><figcaption></figcaption></figure>

## Installation

```bash
pip install akkio
```

## Example Usage

```python
import akkio
akkio.api_key = 'YOUR-API-KEY-HERE' 
# get your API key at https://app.akkio.com/team-settings

# list models in your organization
models = akkio.get_models()['models']
for model in models:
  print(model)

# list datasets in your organization
datasets = akkio.get_datasets()['datasets']
for dataset in datasets:
  print(dataset)

# create a new empty dataset
new_dataset = akkio.create_dataset('python api test')
print(new_dataset)

# add rows to the dataset
import random
rows = []
for i in range(1000):
  rows.append({
    'x': random.random()
  })
  rows[-1]['y'] = rows[-1]['x'] > 0.5
akkio.add_rows_to_dataset(new_dataset['dataset_id'], rows)

# create a model
new_model = akkio.create_model(new_dataset['dataset_id'], ['y'], [], {'duration': 1})
print(new_model)

# make a prediction using the model
prediction = akkio.make_prediction(new_model['model_id'], [{'x': 0.1}, {'x':0.7}], explain=True)
print(prediction)
```

## Datasets

### create\_dataset(dataset\_name)

Create a new empty dataset.

| input         | description                             |
| ------------- | --------------------------------------- |
| dataset\_name | The name of your newly created dataset. |

###

### add\_rows\_to\_dataset(dataset\_id, rows)

Add rows to a dataset.

| input       | description                                                                                                                                 |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| dataset\_id | A dataset id                                                                                                                                |
| rows        | <p>An array of rows to be added to the dataset in the following form: </p><p>\[{ "field 1": "data", "field 2": "data" }, { ... }, ... ]</p> |

###

### get\_datasets()

Get all datasets in your organization.

###

### get\_dataset(dataset\_id)

Get a dataset.

| input       | description  |
| ----------- | ------------ |
| dataset\_id | A dataset id |

### parse\_dataset(dataset\_id)

Recalculate the field types for a dataset.

| input       | description  |
| ----------- | ------------ |
| dataset\_id | A dataset id |

###

### delete\_dataset(dataset\_id)

Delete a dataset.

| input       | description  |
| ----------- | ------------ |
| dataset\_id | A dataset id |

## Models

### get\_models()

Get all models in your organization.

### delete\_model(model\_id)

Delete a model in your organization.

| input     | description |
| --------- | ----------- |
| model\_id | A model id  |

###

### create\_model(dataset\_id, predict\_fields, ignore\_fields, params)

Create a model (requires a dataset).

| input           | description                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| dataset\_id     | A dataset id                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| predict\_fields | An array of field names to predict (case sensitive)                                                                                                                                                                                                                                                                                                                                                                                           |
| ignore\_fields  | An array of field names to ignore (case sensitive) (optional)                                                                                                                                                                                                                                                                                                                                                                                 |
| params          | <p>A dict with default value of:</p><p><code>{</code><br>    <code>"duration": 10,</code></p><p>    <code>"extra\_attention": False,</code></p><p>    <code>"force": False</code><br><code>}</code></p><p><code>duration</code> is the duration in seconds to be used for model training.</p><p><code>extra\_attention</code> can be enabled to help with predicting rare cases</p><p><code>force</code> forces a new model to be created</p> |

{% hint style="info" %}
Sometimes creating models can take a while, especially if this is the first time creating a model on this dataset. **create\_model** is idempotent and can be called multiple times with the same parameters.
{% endhint %}

###

### make\_prediction(model\_id, data)

Make a prediction using your model and new data.

| input     | description                                                                                                                      |
| --------- | -------------------------------------------------------------------------------------------------------------------------------- |
| model\_id | A model id                                                                                                                       |
| data      | <p>An array of rows to be predicted in the following form: </p><p>\[{ "field 1": "data", "field 2": "data" }, { ... }, ... ]</p> |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.akkio.com/akkio-docs/endpoints-and-schemas/additional-libraries/python.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
