# Python SDK

{% hint style="info" %}
Visit our dedicated Python SDK docs [here](https://marpledata.gitlab.io/marple-sdk/)
{% endhint %}

## Installation

Install the package from [PyPi](https://pypi.org/project/marpledata/) using any package manager. Examples:

* `poetry add marpledata`
* `uv add marpledata`
* `pip install marpledata`

## Usage

[Read the full documentation here](https://marpledata.gitlab.io/marple-sdk/)

**Example:** [**import a file and wait for it to import**](https://marpledata.gitlab.io/marple-sdk/tutorials.html#import-a-file-and-wait-for-import)

```python
import time
from marple import DB

# Create a stream + API token in the Marple DB web application
STREAM = "Car data"
API_TOKEN = "<your api token>"
API_URL = "https://db.marpledata.com/api/v1"  # optional if using the default SaaS

db = DB(API_TOKEN, API_URL)

db.check_connection()

stream = db.get_stream(STREAM)
dataset = stream.push_file("examples_race.csv", metadata={"driver": "Mbaerto"})
# Wait at most 10s for the dataset to completely import and get the new state of the dataset
dataset = dataset.wait_for_import(timeout=10)
```

**Example:** [**filter datasets and get resampled data**](https://marpledata.gitlab.io/marple-sdk/tutorials.html#filter-datasets-and-get-resampled-data)

```py
import re
from marple import DB

stream_name = "Car data"
api_token = "<your api token>"

db = DB(api_token)
stream = db.get_stream(stream_name)

datasets = stream.get_datasets()
# Get all datasets where metadata fiedldcar_id is 1 or 2 and track is track_1
datasets = datasets.where_metadata({"car_id": [1, 2], "track": "track_1"})
# Wait for at most 1 minute until all datasets are imported and keep imported datasets
datasets = datasets.wait_for_import().where_imported()
# Filter datasets where a specified signal satisfies a condition
datasets = datasets.where_signal("car.speed", "max", greater_than=75)

# Get the raw data for a set of signals resampled to a common timebase
for dataset, data in datasets.get_data(
    signals=[
        "car.speed",
        re.compile("car.wheel.*.speed"),
        re.compile("car.wheel.*.trq"),
    ],
    resample_rule="0.17s",
):
    # Do something with the data
    model.train(data)

```


---

# 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.marpledata.com/docs/sdk/overview/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.
