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

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

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.26.tar.gz (37.0 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.26-py3-none-any.whl (56.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clarity_api_sdk_python-0.3.26.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clarity_api_sdk_python-0.3.26.tar.gz
Algorithm Hash digest
SHA256 b24b5e704e4b69213e22dad480c35755da2285bab87ddbf1f8fedb1760f77fe1
MD5 114fb23d67c700a1610c9c9a43aa0d60
BLAKE2b-256 152e738b1bd80aee1f73ef216f322c635e3cdfada2c3c9a0c21d125cf5ba51d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for clarity_api_sdk_python-0.3.26.tar.gz:

Publisher: publish.yml on chesapeake-tech/clarity-api-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for clarity_api_sdk_python-0.3.26-py3-none-any.whl
Algorithm Hash digest
SHA256 610e33cf2c51a2bd6f3156510e10af219ed8c6bc783ffe9490711e3d3a7f262a
MD5 ead65b0b7603370ea57e6a7de8b6a57f
BLAKE2b-256 5a974ae5b60de2089d94b9010c3a84a9bf73e0c7233da010f0df537063703af0

See more details on using hashes here.

Provenance

The following attestation bundles were made for clarity_api_sdk_python-0.3.26-py3-none-any.whl:

Publisher: publish.yml on chesapeake-tech/clarity-api-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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