Skip to main content

pycraftcore

pycraftcore is a reusable technical infrastructure library for Python applications: configuration, resilient HTTP clients, a pooled async SQLite repository, a sandboxed Python code runner, safe SQL validation, serialization, and a handful of other adapters — small, swappable building blocks rather than a framework.

Design principles: Modularity · Reusability · Maintainability


Table of Contents


Functionality

Module Package What it gives you
Configuration Management application_configuration Environment-driven YAML configuration for connectors and operations, validated and typed
Authentication application_configuration Shared auth models (none / basic / token) for any connector
Logging logger Structured application logging
Telemetry & Observability telemetry Distributed tracing, exportable to console or an OTLP collector
HTTP Client Utilities http Resilient HTTP client with retries, circuit breaking, and tracing
Repository / SQLite repository Async SQLite repository with real connection pooling for concurrent access
Query Language / SQL Safety query_language Validates that a SQL statement is read-only before it reaches a database
Runtime / Sandboxed Execution runtime Runs untrusted Python code in an isolated process with resource limits
Serialization serialization JSON, dict, and binary (msgpack) serialization for dataclasses
Scientific computation engine computation Financial arithmetic and calculus (integration, interpolation)
File handler file_handler Read/write files by extension, pluggable for new formats
Profiler profiler Async function profiling decorator

Installation

Stable release (recommended for production):

pip install pycraftcore

Development build (latest features, may be unstable):

pip install -i https://test.pypi.org/simple/ pycraftcore

Configuration

Services are configured using YAML files combined with environment variables.

Directory layout — a root.yml plus per-kind subdirectories, one file per item:

Path Description
root.yml Root application configuration (env, run)
connector/*.yml Data source connector definitions
operation/*.yml Retrieval operations and business use cases

Environment variables referenced from YAML via ${oc.env:NAME}:

Variable Used by
APP_ENV root.yml → env
<CONNECTOR_NAME>_API_KEY a connector's auth.key_value
DB_HOST, DB_NAME, DB_USER, DB_PASSWORD a database connector's host/default_name/auth

This list isn't exhaustive — any config value can be templated the same way; check the YAML under config/<env>/ for what a given deployment actually reads.

Connector example (connector/<tag>.yml):

connector:
  <connector_tag>:
    name: <connector name>
    type: api
    base_url: <base url>
    timeout: 5
    retry: 3
    auth:
      type: token
      key_name: apikey
      key_value: ${oc.env:connector_api_key}

Operation example (operation/<tag>.yml) — references a connector by tag:

operation:
  <operation_tag>:
    name: <operation name>
    type: api
    connector: ${connector.<connector_tag>}
    endpoint: /<path>
    method: GET
    parameters:
      <param>: <value>

Root example (root.yml) — wires everything together for a given environment:

application_configuration:
  env: ${oc.env:APP_ENV,debug}
  run: async

  connector:
    api:
      <connector_tag>: ${connector.<connector_tag>}
    file:
      <connector_tag>: ${connector.<connector_tag>}
    database:
      <connector_tag>: ${connector.<connector_tag>}
    telemetry:
      <connector_tag>: ${connector.<connector_tag>}
    
  operation:
    <operation_tag>: ${operation.<operation_tag>}
    # ...

Connectors and operations both declare a type, which determines which fields they take and which concrete object they load as.

Using it in code:

from pathlib import Path

from pycraftcore.application_configuration.adapter.load_application_configuration import (
    LoadApplicationConfiguration,
)
from pycraftcore.application_configuration.adapter.omega_configuration_reader import (
    OmegaConfigurationReader,
)
from pycraftcore.application_configuration.enum.run_type_environment import RunTypeEnvironment
from pycraftcore.logger.adapter.loguru_logger import LoguruLogger

reader = OmegaConfigurationReader(RunTypeEnvironment.deploy, Path("config"))
loader = LoadApplicationConfiguration(reader, LoguruLogger())

config = loader.load()

connector = config.connector.api("<connector_tag>")  # ApiConnector
operation = config.operation.api("<operation_tag>")  # ApiOperation

config.connector/config.operation return the concrete connector/operation type for a given tag (.api(), .database(), .file(), .telemetry() where applicable) instead of a raw dict — see pycraftcore.application_configuration for the full API.


Development

Pre-commit hooks

This repo uses pre-commit to run the unit test suite before every commit and push (see .pre-commit-config.yaml). Git hooks live under .git/hooks/ and aren't tracked by git, so after cloning or pulling this change, install them once:

uv run pre-commit install --hook-type pre-commit --hook-type pre-push

After that, git commit and git push will run uv run pytest automatically and abort on failure. To run the hooks manually against the whole repo:

uv run pre-commit run --all-files --hook-stage pre-commit

Makefile commands

make install_dev   # uv sync --group dev
make test           # uv run pytest
make lint            # uv run ruff check
make format          # uv run ruff format
make typecheck        # uv run ty check (strict mode)

Run pytest --cov=pycraftcore --cov-report=term-missing for a coverage breakdown by module.

Metadata

Release files for pycraftcore 1.3.0

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

Source distribution (sdist)

Source distribution for pycraftcore 1.3.0
File Size Uploaded
pycraftcore-1.3.0.tar.gz 44.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycraftcore 1.3.0
File Interpreter ABI Platform
pycraftcore-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 134.4 kB

Release files / pycraftcore-1.3.0.tar.gz

Download URL pycraftcore-1.3.0.tar.gz
Size 44.2 kB
Tags Source
SHA-256 checksum
How to use checksums
94a80ad0d380c84e773cf9dc41c145879128dd9ca31613a57961004d1ccd8b8c
BLAKE2b-256 checksum
How to use checksums
cf2914a63a4d5b3c833962ab84520f6860cc45f2e665d7cc8e080afa7f638965
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pycraftcore-1.3.0-py3-none-any.whl

Download URL pycraftcore-1.3.0-py3-none-any.whl
Size 90.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea9437354f86629585becd144cb971aa00b0f301d0660c13f811246a063091e9
BLAKE2b-256 checksum
How to use checksums
b0a5440a250177bd34fa1a9510936ef685a878821943c45ef21f45c863c54bf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

2.0.1

2 release files

2.0.0

2 release files

1.6.0

2 release files

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

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