Skip to main content

KeborMed LEDSAS SDK (Python)

CI PyPI version Python versions License: Apache-2.0

A Python client SDK for building LEDSAS (Local External Data Sources Action Service) data-processing services. You write async handler functions; the SDK consumes command messages from RabbitMQ, runs your handler, reads and writes payloads in Azure Blob Storage, and (optionally) publishes the response back to the caller.

It handles the plumbing — message consumption, acknowledgement, retries, timeouts, structured logging, health/readiness endpoints, and blob I/O — so your service code stays focused on the data transformation.


Features

  • Handler-based programming model — register async handlers with a decorator.
  • RabbitMQ consumption with prefetch, bounded concurrency, ack/nack semantics, and a dead-letter path for poison messages.
  • Azure Blob Storage helpers: download_bytes/text/json/stream, upload_bytes/text/json, and memory-bounded streaming for large files.
  • Typed models (Pydantic v2) for blob references and message envelopes.
  • Built-in retries & timeouts with permanent vs. transient error classes.
  • Health & readiness HTTP endpoints (/health, /ready, /livez, /readyz) with pluggable liveness/readiness checks.
  • Structured JSON logging out of the box.
  • Fully type-hinted (py.typed), Python 3.11+.

Installation

Requires Python 3.11 or newer.

pip install kbm-ledsas-sdk

To work from a clone — or before a release is published to PyPI — install from source:

git clone https://github.com/Kubyk-Health/kbm-ledsas-sdk.git
cd kbm-ledsas-sdk
pip install -e .            # add "[dev]" for the test/lint toolchain: pip install -e ".[dev]"

Quickstart

import logging
from kbm_ledsas_sdk import ServiceApp, errors

logging.basicConfig(level=logging.INFO)

app = ServiceApp(service_name="csv-processor")


@app.handler("ProcessCSV")
async def handle(ctx, req: dict) -> dict:
    csv_uri = req.get("csv_uri")
    if not csv_uri:
        # user_message is what the caller sees; the internal message goes to logs.
        raise errors.Permanent(
            "Validation: csv_uri missing",
            user_message="csv_uri is required",
        )

    text = await ctx.blob.download_text(csv_uri)
    container = csv_uri.replace("azblob://", "").split("/", 1)[0]

    out = await ctx.blob.upload_json(
        container=container,
        obj={"rows": len(text.splitlines()) - 1},
        # Use idempotency_key (not message_id) so a redelivery of the same logical
        # request overwrites the same blob. overwrite=True is required for that.
        path=f"result-{ctx.idempotency_key}.json",
        overwrite=True,
    )
    return {"result_uri": out.uri}


# Optional readiness hook (the SDK ships sensible defaults; this layers on top).
@app.readiness_check("warmup_done")
def _() -> bool:
    return True


if __name__ == "__main__":
    app.run()

Run it against a local RabbitMQ + Azure Blob (Azurite):

export KBM_LEDSAS_RABBITMQ_URL="amqp://guest:guest@127.0.0.1:5672/"
export KBM_LEDSAS_BLOB_CONN_STRING="DefaultEndpointsProtocol=http;AccountName=...;AccountKey=...;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;"
python my_service.py

The service also exposes health endpoints at http://127.0.0.1:8090/health and /ready (loopback only by default; set KBM_LEDSAS_HEALTH_HOST=0.0.0.0 to bind all interfaces).

Local development

A ready-to-run stack (RabbitMQ + Azurite) is provided with the example service:

cd examples/hello_world_service
pip install -e ../..                                        # install the SDK from this repo
docker compose -f deploy/local/docker-compose.yml up -d     # start RabbitMQ + Azurite
python main.py                                              # run the example service

See examples/hello_world_service/ for a complete, runnable service (handler, sender script, tests, Dockerfile, and a local docker compose stack under deploy/local/).

Configuration

The SDK is configured through environment variables. The most common are below; see the API reference for the complete list (including KBM_LEDSAS_ALLOW_INSECURE_AMQP, KBM_LEDSAS_MAX_PAYLOAD_BYTES, and other advanced settings):

Variable Description Default
KBM_LEDSAS_SERVICE_NAME Service name used for message routing (required)
KBM_LEDSAS_TENANT Tenant identifier (optional)
KBM_LEDSAS_RABBITMQ_URL RabbitMQ connection URL (required)
KBM_LEDSAS_BLOB_CONN_STRING Azure Blob Storage connection string (required)
KBM_LEDSAS_CONTAINER Default blob container dev
KBM_LEDSAS_PREFETCH AMQP prefetch count 10
KBM_LEDSAS_CONCURRENCY Worker concurrency 4
KBM_LEDSAS_HANDLER_TIMEOUT Per-handler timeout (seconds) 1800
KBM_LEDSAS_MAX_RETRIES Max retries for transient failures 3
KBM_LEDSAS_LOG_LEVEL Log level INFO
KBM_LEDSAS_LOG_FORMAT Log format (json or text) json
KBM_LEDSAS_HEALTH_HOST Health server bind host 127.0.0.1
KBM_LEDSAS_HEALTH_PORT Health server port 8090
KBM_LEDSAS_DEPLOYMENT_ID Build/commit id surfaced as deployment_id in /health and /ready (optional)

Documentation

Contributing

Contributions are welcome! Please read CONTRIBUTING.md first — it covers the development setup, how to run the tests, the coding style, and the Developer Certificate of Origin (DCO) sign-off we require on every commit. Also see our Code of Conduct.

Security

Please report vulnerabilities privately — see SECURITY.md. Do not open a public issue for security reports.

License

Licensed under the Apache License 2.0. Copyright © 2025-2026 KeborMed. See THIRD_PARTY_NOTICES.txt for third-party dependency licenses.

Maintained by KeborMed (the software's copyright holder) under the Kubyk-Health GitHub organization.

Metadata

Release files for kbm-ledsas-sdk 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kbm-ledsas-sdk 0.3.3
File Size Uploaded
kbm_ledsas_sdk-0.3.3.tar.gz 81.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kbm-ledsas-sdk 0.3.3
File Interpreter ABI Platform
kbm_ledsas_sdk-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 177.7 kB

Release files / kbm_ledsas_sdk-0.3.3.tar.gz

Download URL kbm_ledsas_sdk-0.3.3.tar.gz
Size 81.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f3d263f0b1a307d7f86b9649d4563453b7328f53ffcbc74908caba6933f7bdaf
BLAKE2b-256 checksum
How to use checksums
fb8e55f9e5ab8c7f369dd8300eacaec757b21eb18f956682d7a428ee74c2d617
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 10, 2026.

Transparency log

Release files / kbm_ledsas_sdk-0.3.3-py3-none-any.whl

Download URL kbm_ledsas_sdk-0.3.3-py3-none-any.whl
Size 95.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1e9487962d878fd29f0c99ee74893d560c87d25746986fd7cd3d60bb4a30dce
BLAKE2b-256 checksum
How to use checksums
4fec15ce4408161d0ca9277c523e6996885ab0f2dec8352cb836ab45f78a46f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 10, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page