Cledar Python SDK
Project Description
Cledar Python SDK is a shared set of production‑ready services and utilities used across Cledar projects. It can be installed from PyPI (recommended), or consumed as a Git dependency or Git submodule.
Included modules:
- kafka_service: Kafka Producer/Consumer, helpers and DLQ handler
- storage_service: Object storage abstraction (S3/ABFS/local via fsspec)
- monitoring_service: FastAPI monitoring server with Prometheus metrics and healthchecks
- redis_service: Redis‑backed typed config store
- kserve_service: KServe helpers
- common_logging: Common logging utilities
Installation and Setup
-
From PyPI (recommended)
Using pip:
pip install cledar-sdk
Using uv:
uv add cledar-sdk
Pin a specific version (example):
pip install "cledar-sdk==1.0.1"
-
From Git (alternative)
Using pip (SSH, specific tag):
pip install "git+ssh://git@github.com/Cledar/cledar-python-sdk.git@v1.0.1"
Using uv (SSH, specific tag):
uv add --git ssh://git@github.com/Cledar/cledar-python-sdk.git@v1.0.1
You can also point to a branch (e.g.
main) instead of a tag. -
As a Git submodule
git submodule add git@github.com:Cledar/cledar-python-sdk.git vendor/cledar-python-sdk git submodule update --init --recursive
Optionally install it in editable mode from the submodule path:
uv add -e ./vendor/cledar-python-sdk
-
Developing locally
git clone git@github.com/Cledar/cledar-python-sdk.git cd cledar-python-sdk uv sync
Python version required: 3.12.7
Testing
Unit tests are implemented using pytest and unittest.
-
Run tests:
uv run pytest
-
Adding tests: Place tests under each module's
testsdirectory (e.g.kafka_service/tests,storage_service/tests) or create files with the_test.pysuffix.
Quick Start Examples
Kafka
Producer:
from kafka_service.clients.producer import KafkaProducer
from kafka_service.config.schemas import KafkaProducerConfig
cfg = KafkaProducerConfig(
kafka_servers="localhost:9092",
kafka_group_id="example",
kafka_topic_prefix="dev",
compression_type="snappy",
kafka_partitioner="consistent_random",
)
producer = KafkaProducer(config=cfg)
producer.connect()
producer.send(topic="my-topic", value='{"id":"123","payload":"hello"}', key="123")
Consumer:
from kafka_service.clients.consumer import KafkaConsumer
from kafka_service.config.schemas import KafkaConsumerConfig
cfg = KafkaConsumerConfig(
kafka_servers="localhost:9092",
kafka_group_id="example",
kafka_topic_prefix="dev",
kafka_offset="earliest",
kafka_auto_commit_interval_ms=5000,
)
consumer = KafkaConsumer(config=cfg)
consumer.connect()
consumer.subscribe(["my-topic"])
msg = consumer.consume_next()
if msg:
consumer.commit(msg)
Object Storage (S3/ABFS/local)
from storage_service.object_storage import ObjectStorageService
from storage_service.models import ObjectStorageServiceConfig
cfg = ObjectStorageServiceConfig(
s3_access_key="minioadmin",
s3_secret_key="minioadmin",
s3_endpoint_url="http://localhost:9000",
)
storage = ObjectStorageService(config=cfg)
storage.upload_file(
file_path="README.md",
destination_path="s3://bucket/path/README.md",
)
Monitoring Server
from cledar.monitoring import MonitoringServer, MonitoringServerConfig
config = MonitoringServerConfig(
readiness_checks={"s3": storage.is_alive},
liveness_checks={"app": lambda: True},
)
server = MonitoringServer(host="0.0.0.0", port=8080, config=config)
server.start_monitoring_server()
Redis Config Store
from redis import Redis
from redis_service.redis_config_store import RedisConfigStore
redis = Redis(host="localhost", port=6379, db=0)
store = RedisConfigStore(redis=redis, prefix="example:")
# See redis_service/example.py for a full typed config provider example
Code Quality
- pydantic - settings management
- ruff, mypy - Linting, formatting, and static type checking
- pre-commit - Pre-commit file checks
Linting
If you want to run linting or type checker manually, you can use the following commands. Pre-commit will run these checks automatically before each commit.
uv run ruff format .
uv run ruff check .
uv run mypy .
Pre-commit setup
To get started follow these steps:
-
Install
pre-commitby running the following command:pip install pre-commit -
Once
pre-commitis installed, set up the pre-commit hooks by running:pre-commit install -
Pre-commit hooks will analyze only committed files. To analyze all files after installation run the following:
pre-commit run --all-files
Automatic Fixing Before Commits:
pre-commit will run Ruff (format + lint) and mypy during the commit process:
git commit -m "Describe your changes"
To skip pre-commit hooks for a single commit, use the --no-verify flag:
```bash
git commit -m "Your commit message" --no-verify
```
Technologies and Libraries
Main Dependencies:
- python >= "3.12.7"
- pydantic-settings
- confluent-kafka
- fastapi
- prometheus-client
- uvicorn
- redis
- fsspec/s3fs/adlfs (S3/ABFS backends)
- boto3 and boto3-stubs
Developer Tools:
- uv - Dependency and environment management
- pydantic - settings management
- ruff - Linting and formatting
- mypy - Static type checker
- pytest, unittest - Unit tests
- pre-commit - Code quality hooks
Commit conventions
We use Conventional Commits for our commit messages. This helps us to create a better, more readable changelog.
Example of a commit message:
refactor(XXX-NNN): spaghetti code is now a carbonara
Metadata
Release files for cledar-sdk 2.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cledar_sdk-2.3.0.tar.gz | 95.7 kB | Without provenance | Details for cledar_sdk-2.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cledar_sdk-2.3.0-py3-none-any.whl | Python 3 | none | any | Details for cledar_sdk-2.3.0-py3-none-any.whl |
Total release size: 229.1 kB
Release files / cledar_sdk-2.3.0.tar.gz
| Download URL | cledar_sdk-2.3.0.tar.gz |
|---|---|
| Size | 95.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
701ac8c8e9b58397398d56811cadd128c06fbe2fd93bf2c5b8f3f38d23dcba3e
|
|
BLAKE2b-256 checksum How to use checksums |
5d2c3f22b49d706e36a11da8a0e519008bd4adb4f70f83ab9be86937b473b2c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cledar_sdk-2.3.0-py3-none-any.whl
| Download URL | cledar_sdk-2.3.0-py3-none-any.whl |
|---|---|
| Size | 133.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca21688b049289f45cba1fb05bf10fa779672dc306d5e6bd74cfae0be46f5202
|
|
BLAKE2b-256 checksum How to use checksums |
effe22ff4c0fe19e7c5f09c4abaf53268b33e78425a53fd84d3a6c98787db5f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for cledar-sdk 2.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.