Skip to main content

Shared config, logging, cache and common tooling for 40F services.

Project description

f40-toolkit

Shared configuration, logging, caching, and common utilities used across 40F services.

This repository is structured as a standard Python package (src/ layout) and is intended to be consumed by multiple internal projects. The documentation is designed to be usable directly from the repository (Bitbucket renders Markdown), and can optionally be served locally as a browsable site.

Requirements

  • Python 3.12+ (requires-python = ">=3.12")

Installation

Core package (minimal dependencies):

pip install f40-toolkit

Optional features (extras):

# Cache extras (memory/file backends only; no additional dependencies)
pip install f40-toolkit[cache]

# Cache + Redis backend (pulls redis>=5)
pip install f40-toolkit[cache-redis]

# YAML support for config loading (pulls pyyaml>=6)
pip install f40-toolkit[config]

# Convenience install of all optional features
pip install f40-toolkit[all]

What’s included

  • f40_toolkit.cache — Cache manager + backends (memory, file, redis), key builder, health check, and basic observability hooks.
  • f40_toolkit.config — Configuration loading helpers (including optional YAML support).
  • f40_toolkit.logging — Structured logging configuration and session helpers.
  • f40_toolkit.common — Small reusable utilities (env, dict helpers, redaction, filesystem helpers, etc.).

Quickstart

Cache (recommended entry point)

Create a cache from a simple config dict:

from f40_toolkit.cache import create_cache_from_config, InvalidCacheValue

cfg = {
    "env": "prod",
    "service": {"name": "billing"},
    "customer": "acme",
    "cache": {
        "backend": "memory",          # "file" | "memory" | "redis"
        "default_timeout": 300,       # seconds
        "serializer": "json",         # currently: "json"
        # For file backend only:
        # "path": ".cache",
        # For redis backend only:
        # "redis": {"url": "redis://localhost:6379/0"}
    },
}

cache = create_cache_from_config(cfg)

cache.set("example", {"ok": True}, timeout=60)

try:
    value = cache.get("example")
except InvalidCacheValue:
    value = None

print(value)

Memoization helper:

def expensive(a: int, b: int) -> int:
    return a + b

value = cache.get_or_set(
    key="sum:1:2",
    func=expensive,
    f_args=[1, 2],
    timeout=120,
)
print(value)

Redis backend (optional):

# pip install f40-toolkit[cache-redis]
from f40_toolkit.cache import create_cache_from_config

cfg = {
    "env": "prod",
    "service": {"name": "billing"},
    "customer": "acme",
    "cache": {
        "backend": "redis",
        "default_timeout": 300,
        "serializer": "json",
        "redis": {
            "url": "redis://localhost:6379/0",
            # Optional explicit prefix override:
            # "prefix": "prod:acme:billing:cache:",
        },
    },
}

cache = create_cache_from_config(cfg)

Local documentation (no hosting required)

Markdown docs can be read directly in Bitbucket once committed.

If you also want a locally served documentation site (recommended for larger docs sets), use MkDocs:

  1. Add a docs/ directory with Markdown files (and optionally a mkdocs.yml at repo root).
  2. Install docs tooling and run a local server:
pip install -e .[docs]
mkdocs serve

Then open the local URL printed by mkdocs serve in a browser.

Note: The docs extra is not yet defined in pyproject.toml in this repository. If you want MkDocs support, add an extra such as:

[project.optional-dependencies]
docs = ["mkdocs", "mkdocs-material", "mkdocstrings[python]", "mkdocs-autorefs"]

Development

pip install -e .[dev]
pytest
ruff check .
mypy src

Build and check distribution artifacts:

python -m build
twine check dist/*

License

MIT. See LICENSE.

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

f40_toolkit-0.1.5.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

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

f40_toolkit-0.1.5-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file f40_toolkit-0.1.5.tar.gz.

File metadata

  • Download URL: f40_toolkit-0.1.5.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for f40_toolkit-0.1.5.tar.gz
Algorithm Hash digest
SHA256 f003215262fa11ff47e7ee67dfabdffb7c1ceeb0a6e15a0d5f103b8c5954d6d4
MD5 e6c866b587e1d13d3836eaafacd1aef6
BLAKE2b-256 199d9495e1a48be619e99caf97d57611dbccce896c2bab36615208100ea05f09

See more details on using hashes here.

File details

Details for the file f40_toolkit-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: f40_toolkit-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for f40_toolkit-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1deba9de62fd1d3c520b0d6e8578cfbf8989f8cdb7cde5e060bc8c3201f8643c
MD5 d1f7646c9afbc2c22ac6e215cdb01202
BLAKE2b-256 2bb4b92139d0c76884fd83c35bb91d7a36e57caa454da16e0f4a9e416d066d7f

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