Skip to main content

A Python SDK to connect to the CTI Clarity API server.

Project description

Clarity API SDK for Python

PyPI - Downloads Downloads python

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

Installation

pip install clarity-api-sdk-python

Logging

Logging support is built with structlog.

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

"""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")

Model

Pydantic models.

API

Singleton async client

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clarity_api_sdk_python-0.3.16.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clarity_api_sdk_python-0.3.16-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

Details for the file clarity_api_sdk_python-0.3.16.tar.gz.

File metadata

  • Download URL: clarity_api_sdk_python-0.3.16.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for clarity_api_sdk_python-0.3.16.tar.gz
Algorithm Hash digest
SHA256 0193d1865f7dca9046f13486c1255e2ef6f6721ba11eb6f5eaee72df60129de4
MD5 bd8b8ac00d13af91917cae3f244d07ac
BLAKE2b-256 77ffc5e3ad0ac3ee501a10e9511dc7d5bd69949536cefe9b35652900a8b845fc

See more details on using hashes here.

File details

Details for the file clarity_api_sdk_python-0.3.16-py3-none-any.whl.

File metadata

File hashes

Hashes for clarity_api_sdk_python-0.3.16-py3-none-any.whl
Algorithm Hash digest
SHA256 0e224d679473734342dcd6c4715a69f673559fc497c3f667bce8a08fb16ce717
MD5 98446d86e536a3ecdcd8bb24c27c0cce
BLAKE2b-256 2c983006a2b07ddb02e55e097e7d095212d38cf22fc247ef416d1cea78beff9a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page