Skip to main content

Forge your application registries.

Project description

Tamahagane

Documentation Continuous Integration Coverage Report

Forge your application registries.

Tamahagane is a library designed for constructing application registries, the essential foundation for building decoupled software architectures and enabling unit testing on application handlers.

Motivation

Tamahagane essentially serves as a modern alternative to Venusian, fulfilling the same core functionality.

The decision to create a new library stems from Venusian's limitations: it was originally built for Python 2, relies heavily on dynamic behavior, and lacks type support.

Tamahagane reuse the same vocabular, a Scanner and an attach function, but the API is not fully compatible, in order to get a simpler version.

Usage

To use Tamahagane you need to create a registries class that hold all registries your app may load. The definition of the registry is free and depends of the usage.

from dataclasses import dataclass

@dataclass
class Registries:
    app_registry: ...

After what, the registries is filled out using the scan of the application code.

import tamahagane as th

scanner = th.Scanner[Registries](Registries(app_registry=...))
scanner.scan("app.service_handlers")

At this time, the app.service_handlers is a module, or a package containing submodules, that will be recursibely loaded. It contains decorated function, where the decorator has been created in the application code to create the callback.

from collections.abc import Callable
from typing import Any

import tamahagane as th


CommandHandler = Callable[..., Any]

def command_handler(wrapped: CommandHandler) -> CommandHandler:

    def callback(registries: Registries) -> None:
        registries.app_registry.do_something_with(wrapped, ...)

    th.attach(wrapped, callback, category="app_registry")
    return wrapped

Now, you have a command_handler decorator that can be used an be filled out an application registry with the decorated method.

@command_handler
def handle_stuff(...):
    ...

handle_stuff is unmodified by its decorator and is purely unit testable. No overhead.

Difference from Venusian

  • Tamahagane supports absolute and relative name of module on scanner method scan.
  • Tamahagane does not have a onerror on the scan method, it raises.
  • Tamahagane does not have a category on the scan method, the categories are the attributes of the registry, nothing less, nothing more.
  • Tamahagane does not support class decoration.

Installation

Tamahagane is available on PyPI

So you can installing using your favorite packaging tool, mine is uv:

uv add tamahagane

List of libraries using Tamahagane

Here is a curative list of projects using tamahagane:

Library Description Repository
fastlife A web framework that register routes, templates and more using th. github.com/mardiros/fastlife
messagebus A message bus implementation for Python applications. github.com/mardiros/messagebus
whitesmith A testing library for blacksmith rest client. It scan routes, like a read web framework. github.com/mardiros/whitesmith

See also

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

tamahagane-0.4.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

tamahagane-0.4.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file tamahagane-0.4.2.tar.gz.

File metadata

  • Download URL: tamahagane-0.4.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.26.6 CPython/3.12.12 Linux/6.11.0-1018-azure

File hashes

Hashes for tamahagane-0.4.2.tar.gz
Algorithm Hash digest
SHA256 9c3951d1bac8970751447e69f928e3e066f7c3c1a2c89e94f16a0610f58d96f5
MD5 97380bff8cb3c3f15a912e0b10e0b757
BLAKE2b-256 673de56424541343ebc0691dc5b0b560fa080be8da0f5c5823bb0ee7b3b08ee7

See more details on using hashes here.

File details

Details for the file tamahagane-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: tamahagane-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.26.6 CPython/3.12.12 Linux/6.11.0-1018-azure

File hashes

Hashes for tamahagane-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f9e31d8e71c7af028cbdfdc335df0fc45b61c97af09d65591be6917e3141ceff
MD5 96c106c40a2197bca876e5820cd58a49
BLAKE2b-256 8ef69ee54b9570295ef5ac3ab66b37a67a0de5d00487d02be58f476d55e1f947

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