Skip to main content

Shared utilities, contracts, and middleware for KubeMind services

Project description

KubeMind Common Library

Shared Python library for all KubeMind services.

Overview

kubemind-common provides shared functionality across all KubeMind services:

  • Configuration management
  • Logging setup with correlation IDs
  • Middleware (request ID, rate limiting, error handling)
  • Contracts (Pydantic models for events, playbooks, triggers)
  • HTTP client with retries
  • Redis client and utilities
  • Database utilities
  • Security utilities (JWT, HMAC)
  • Metrics instrumentation
  • Kubernetes utilities

Contributor Guide

See Repository Guidelines for structure, workflows, and review expectations.

Installation

  • From PyPI:
pip install kubemind-common
  • With extras (examples):
pip install "kubemind-common[fastapi]"
pip install "kubemind-common[db]"
pip install "kubemind-common[auth]"
  • In a monorepo (editable install):
pip install -e ../kubemind-common

Development

pip install -e .[dev]

Running the test suite and building artefacts are managed through the bundled Makefile:

make test   # run pytest after a clean build directory
make build  # produce wheel and sdist under dist/
make check  # twine check on the build outputs

Publishing

  1. Export a PYPI_TOKEN with upload permissions (username is always __token__).
  2. Run make publish which will rebuild, validate and upload using Twine.
  3. Tag the release (git tag vX.Y.Z && git push --tags) so downstream services can pin versions.

Usage

Configuration

from kubemind_common.config.base import BaseServiceSettings

settings = BaseServiceSettings()

Logging

from kubemind_common.logging.setup import setup_logging

setup_logging(level="INFO", format="json")

HTTP Client

from kubemind_common.http.client import create_http_client, http_request

async with create_http_client() as client:
    response = await http_request(client, "GET", "https://api.example.com")

Kubernetes

from kubemind_common.k8s.client import create_k8s_client

k8s = create_k8s_client(in_cluster=False)
pods = k8s.core_v1_api.list_pod_for_all_namespaces()

Contracts

from kubemind_common.contracts.events import Event
from kubemind_common.contracts.playbooks import PlaybookSpec

event = Event(
    id="evt-123",
    source="kubernetes",
    type="pod_crash",
    timestamp="2025-10-12T17:00:00Z"
)

Project Structure

  • src/kubemind_common/ — library code
    • config/, logging/, middleware/, contracts/, http/, redis/, db/, security/, metrics/, k8s/, utils/, etc.
  • tests/ — unit and integration tests
  • docs/ — documentation (see docs/index.md)
  • examples/ — runnable usage examples
  • .github/workflows/ — CI/CD and publishing

Development

# Create a virtual environment and install in editable mode
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"

# Run tests
pytest

# Type checking (if configured)
mypy src/kubemind_common/

# Linting (if configured)
ruff check .

Build & Publish

This project uses modern PEP 621 metadata with Hatchling.

  • Local build:
python -m pip install --upgrade build
python -m build
  • Trusted Publishing via GitHub Actions:
    • Configure the PyPI project to trust this repository (PyPI → Management → Publishing → Trusted Publishers).
    • Tag a release vX.Y.Z to publish to PyPI.
    • Tag a pre-release like vX.Y.Z-rc1 to publish to TestPyPI.
    • Or run the Publish workflow manually and choose pypi or testpypi.

Versioning

This library follows semantic versioning. Services should pin compatible versions:

kubemind-common = "^0.2.0"

Documentation

See docs/index.md for module documentation and examples.

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

kubemind_common-0.1.0.tar.gz (42.2 kB view details)

Uploaded Source

Built Distribution

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

kubemind_common-0.1.0-py3-none-any.whl (56.3 kB view details)

Uploaded Python 3

File details

Details for the file kubemind_common-0.1.0.tar.gz.

File metadata

  • Download URL: kubemind_common-0.1.0.tar.gz
  • Upload date:
  • Size: 42.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.4

File hashes

Hashes for kubemind_common-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ac77f7984ff76053f1fa62d24fe637f219983dfb36412f062beaee80dc78d219
MD5 dd80798b19fa1a3130bd0cb29fc34712
BLAKE2b-256 59b0a672805ac10d77d73106430fe99ff9b88173acc3f65e6e190a2505b0528c

See more details on using hashes here.

File details

Details for the file kubemind_common-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for kubemind_common-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49d4b8d8decb465eb2c56d23e9f51a9a82e8e5a08de4eb3088485d0eceac306b
MD5 694416efdbca518f76a70ebb1eee1381
BLAKE2b-256 e5baecbe25fa2a17c7433a3ab8d1470419a8e4af13b0776e4d3df471dc5f6d97

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