Skip to main content

Core utilities for Kat-based microservices

Project description

corekat-light

corekat is a powerful, asynchronous Python toolkit providing shared utilities for Kat-based microservices. It offers robust configuration management, pluggable file download capabilities, foundational async client infrastructure, and standardized exception handling.

Key Features

  • Type-Safe Configuration: Manage your application's settings with Pydantic V2, loading from YAML files and environment variables with a clear hierarchy.
  • Exception Hierarchy: Standardized exceptions with HTTP status mapping, structured error details, and automatic serialization.
  • String & Dict Utilities: Case conversion (to_snake_case, to_pascal_case, to_kebab_case) and dictionary flattening/unflattening for config transformations.
  • Pluggable Download Client: A fully asynchronous DownloadClient for handling files from HTTP, local storage, and S3 (via StashKat) through a pluggable "fetcher" protocol.
  • Dependency Injection Pattern: Encourages clean architecture by promoting dependency injection for configuration and clients, making your code more modular and easier to test.
  • Async Context Managers: All clients support async with for automatic resource cleanup.

What's New in v3

Exception Hierarchy

Standardized exception handling with automatic HTTP status mapping:

from corekat.exceptions import NotFoundError, ValidationError

# Raise with structured details
raise NotFoundError(
    "User not found",
    details={"user_id": "123"}
)

# Automatic HTTP mapping in ServeKat
# → 404 response with {"code": "not_found", "message": "...", "details": {...}}

String Utilities

Common string transformations for code generation and API design:

from corekat import to_snake_case, to_pascal_case, to_kebab_case

to_snake_case("HelloWorld")    # "hello_world"
to_pascal_case("hello_world")  # "HelloWorld"
to_kebab_case("HelloWorld")    # "hello-world"

Dict Utilities

Flatten and unflatten nested dictionaries for config processing:

from corekat import flatten_dict, unflatten_dict

nested = {"app": {"db": {"host": "localhost"}}}
flat = flatten_dict(nested)
# {"app.db.host": "localhost"}

restored = unflatten_dict(flat)
# {"app": {"db": {"host": "localhost"}}}

Installation

Install the library and its dependencies.

# Core library
uv pip install corekat

# For S3 support, install the stashkat plugin
uv pip install stashkat

# For development with all extras
uv pip install -e ".[dev,all]"

(Requires Python >= 3.12)

Full Documentation

For detailed guides, tutorials, and the API reference, please visit the full documentation site.

Development

  • Setup: uv sync --dev
  • Testing: make test
  • Linting & Formatting: make check and make fix

License

This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.

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

corekat-0.3.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

corekat-0.3.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file corekat-0.3.0.tar.gz.

File metadata

  • Download URL: corekat-0.3.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for corekat-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7320d42ddb260f587c2c59afb19b737afb2647ff3942d05f5a72c6619f712e21
MD5 20395cc8e80ee7e68853226f74005555
BLAKE2b-256 79883c28715a58557f93fbe5b44c1d3de3e27154c0c00436fcc4620830224af2

See more details on using hashes here.

File details

Details for the file corekat-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: corekat-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for corekat-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11ce3ef6425d4cf047d4a91419f2f35a00ae9b7ae5d001d471dfc203f7170f34
MD5 2fa89cd2986f73d01697c3659ef10a60
BLAKE2b-256 35033fcc663eed8af7f581314ac58b8bc38c9b165344d7b5975a85f361de1977

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