Metadata-Version: 2.4
Name: clarity-api-sdk-python
Version: 0.3.22
Summary: A Python SDK to connect to the CTI Clarity API server.
Author-email: "Chesapeake Technology Inc." <support@chesapeaketech.com>
Project-URL: Homepage, https://github.com/chesapeake-tech/clarity-api-sdk-python
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.28.1
Requires-Dist: brotli
Requires-Dist: h2
Requires-Dist: httpx_auth>=0.23.1
Requires-Dist: httpx-retries>=0.4.5
Requires-Dist: pydantic==2.12.3
Requires-Dist: structlog
Provides-Extra: dev
Requires-Dist: black==25.9.0; extra == "dev"
Requires-Dist: build==1.3.0; extra == "dev"
Requires-Dist: mypy==1.18.2; extra == "dev"
Requires-Dist: pre-commit==4.3.0; extra == "dev"
Requires-Dist: pylint==3.3.8; extra == "dev"
Requires-Dist: pytest==8.4.2; extra == "dev"
Requires-Dist: pytest-asyncio==1.3.0; extra == "dev"
Requires-Dist: pytest-md==0.2.0; extra == "dev"
Requires-Dist: pytest-mock==3.15.1; extra == "dev"
Requires-Dist: twine==6.2.0; extra == "dev"
Provides-Extra: brotli
Requires-Dist: httpx[brotli]>=0.28.1; extra == "brotli"
Provides-Extra: http2
Requires-Dist: httpx[http2]>=0.28.1; extra == "http2"

# Clarity API SDK for Python

[![PyPI - Downloads](https://badge.fury.io/py/clarity-api-sdk-python.svg)](https://pypi.org/project/clarity-api-sdk-python/)
[![Downloads](https://pepy.tech/badge/clarity-api-sdk-python)](ttps://test.pypi.org/project/clarity-api-sdk-python/)
![python](https://img.shields.io/badge/python-3.11%2B-blue)

A Python SDK for connecting to the CTI API server, with structured logging included.

## Installation

```bash
pip install clarity-api-sdk-python
```

## Logging

Logging support is built with [structlog](https://pypi.org/project/structlog/).

Set the root logger by setting the environment variable `LOG_LEVEL`. Otherwise, the default root logging is set to `INFO`.

```python
"""Example"""

import logging

from cti.logger import initialize_logger, get_logger, ExternalLoggerConfig

initialize_logger(
    external_logger_configurations=[
        ExternalLoggerConfig(name="urllib3"),
        ExternalLoggerConfig(name="httpcore"),
        ExternalLoggerConfig(name="httpx"),
        ExternalLoggerConfig(name="httpx_auth"),
        ExternalLoggerConfig(name="httpx_retries"),
    ],
    handlers=[logging.FileHandler("app.log")]
)

logger_a = get_logger("logger_a")
logger_b = get_logger("logger_b", "WARNING")

# root_logger = logging.getLogger()
# root_logger.setLevel("DEBUG")

logger_a.info("This is info message from logger_a")
logger_a.critical("This is critical message from logger_a")

# Dynamically change the log level of logger_a to WARNING
print("\nChanging logger_a level to WARNING...\n")
logging.getLogger("logger_a").setLevel(logging.WARNING)

logger_a.info("This info message from logger_a should NOT be visible.")
logger_a.warning("This is a new warning message from logger_a.")

logger_b.info("This info message from logger_b should NOT be visible.")
logger_b.warning("This is warning message from logger_b")

# the value will be redacted
logger_b.info("password", extra={"aws_access_key_id", "AKIAIOSFODNN7EXAMPLE"})
```

## Model

Pydantic models.

## API

### Singleton async client

```python
import asyncio
from cti.api.session import initialize_async_client, close_async_client

async def main():
    await initialize_async_client()
    # ... your application logic ...
    await close_async_client()

if __name__ == "__main__":
    asyncio.run(main())

# In other modules
from cti.api.session import async_client

async def fetch_data():
    if async_client:
        response = await async_client.get(...)
        return response.json()
```
