# python-getstream-connector
Wrapper for official GetStream library (Managed by Terraform)

`getstream-connector` is a wrapper for the official Python library for GetStream, designed to enhance its functionality by adding several key features:

- **Datadog Tracing**: Automatically traces API calls using Datadog.
- **Retry Mechanism**: Implements retry functionality using the `backoff` library to handle transient failures and rate limits.
- **Throttling Mechanism**: Prevents reaching the API rate limit by throttling requests.
- **Trace Context**: Adds trace context to GetStream activity messages.
- **Correlation ID**: Adds correlation ID to GetStream activity messages.

This library is designed for Python 3.11.

## Installation

To install `getstream-connector`, use `pip`:

```bash
pip install getstream-connector
```

## Usage

### Basic Usage

First, import the `getstream-connector` library and initialize the client:

```python
from getstream_connector import get_client

client = get_client(
    api_key='your_api_key',
    api_secret='your_api_secret',
    app_id='your_app_id',  # optional
    location='your_location',  # also optional, but usually need to be set
)

ids = ['123', '456']

# Example usage
response = client.get_activities(ids)
print(response)
```

### Features

#### Datadog Tracing

The library automatically traces API calls using Datadog. Ensure Datadog is properly configured in your environment.

#### Retry Mechanism

Retries are automatically handled using the `backoff` library. For now, retry happens only in case of rate limit reach.

#### Throttling Mechanism

The library includes a throttling mechanism to prevent reaching the API rate limit, ensuring compliance with GetStream's rate limits.

#### Trace Context and Correlation ID

The library injects trace context and correlation IDs into GetStream activity messages, aiding in tracking and debugging across distributed systems.

## Development

This project uses `pre-commit` to enforce code style and static typing checks before commits. All development dependencies can be installed by:

```bash
pip install -r requirements-dev.txt
pre-commit install
```

### Makefile

A `Makefile` is provided with several useful functions:

- **test**: Run tests
- **fix_style**: Fix code style using `ruff check --fix` and `ruff format`
- **check_style**: Check code style using `ruff check`
- **check_types**: Check static typing using `mypy`
- **run_check_suite**: Run the full check suite (`check_style`, `check_types`, `test`)
- **docker/%**: Run any of the above commands in Docker

#### Running Commands

All make commands can be run like `make COMMAND_NAME`. For example, to run tests:

```bash
make test
```

#### Running Commands in Docker

To run any command in Docker, use the `docker/%` target. For example, to run tests in Docker:

```bash
make docker/test
```
