Skip to main content

Canary Framework — lightweight decorator-driven Python service framework

Reason this release was yanked:

0.4版本进行了破坏性重构,我做了很多更好的设计

Project description

Canary Framework

Lightweight Python Service Framework — Decorator-Driven, Zero Boilerplate

License Python


Canary Framework is a decorator-driven service framework. Core philosophy: Services are the minimum unit. Modules compose services. Modules themselves are also services.

Features

  • Decorator API@service / @module / @config, no base class inheritance needed
  • Topological Startup — Kahn's algorithm ensures dependencies start first
  • Dependency Injectiondeps=[DBService] auto-injected as self.db_service
  • Config Management@config + pydantic-settings, auto-reads .env and env vars
  • Lifecycle Hooks@on_init / @on_start / @on_end, sync/async adaptive
  • Web IntegrationWebCanary for one-click FastAPI + Uvicorn
  • Context System — parent chain delegates config and dependency resolution upward
  • Type Safetyctx.get_config(Type) / ctx.get_service(Type) with full IDE inference
  • Log Sanitization — sensitive config fields (password, secret, token) automatically masked

Installation

pip install canary-framework          # core library
pip install canary-framework[web]     # with FastAPI support

Quick Start

import asyncio
from canary_framework import service, module, on_start, Canary

@service(name="hello")
class HelloService:
    @on_start
    def start(self) -> None:
        print("Hello from Canary!")

@module(name="App", services=[HelloService])
class App:
    pass

if __name__ == "__main__":
    async def main() -> None:
        app = Canary(App)
        await app.init()
        await app.start()

    asyncio.run(main())

Web Example

import asyncio
from canary_framework import config, module
from canary_framework.web.fastapi import web, get, WebCanary

@config
class AppConfig:
    uvicorn_host: str = "127.0.0.1"
    uvicorn_port: int = 8000
    fastapi_title: str = "My API"

@web()
@module(name="AppModule", config=AppConfig, services=[])
class AppModule:
    @get("/health")
    async def health(self) -> dict:
        return {"status": "ok"}


async def main() -> None:
    app = WebCanary(AppModule)
    await app.init()
    await app.start()

asyncio.run(main())

Documentation

📖 Full documentation: Canary Framework Docs

中文文档: docs/zh/ · English: docs/en/

Architecture

src/canary_framework/
├── core/
│   ├── decorators/          # @config, @service, @module, @on_init/start/end
│   ├── engine/              # Canary, Context, Injector, Sorter
│   ├── registry/            # Registry (dataclass ServiceEntry)
│   └── utils/               # Naming utilities
└── web/
    └── fastapi/             # WebCanary engine, @web, @router, @get/@post/...
Canary.init()
  ├── _collect()            recursively discover @service/@module
  ├── _validate()           validate dependency integrity
  ├── topological_sort()    Kahn topological sort
  ├── _build_context_tree() build Context parent chain
  └── per topology: DI → config loading → on_init(ctx)
Canary.start()
  └── per topology: on_start()
Canary.stop()
  └── reverse order: on_end()

Community

Contributing

See CONTRIBUTING.md.

License

Apache 2.0 · Copyright 2026 张文博 (Canary)

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

canary_framework-0.3.0.tar.gz (66.4 kB view details)

Uploaded Source

Built Distribution

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

canary_framework-0.3.0-py3-none-any.whl (43.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: canary_framework-0.3.0.tar.gz
  • Upload date:
  • Size: 66.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for canary_framework-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8759a5d407473ba6a73b1dfb4e6c38e4cfb481c86e484ec16091536950d3aad8
MD5 8cbd69c9510ee2da52345c159cf52904
BLAKE2b-256 aa76a7eff4be7bf6e78ebc0c7f6f0ce0b570a2a47ff933444797e45b8f5a28fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for canary_framework-0.3.0.tar.gz:

Publisher: publish.yml on HotcocoaCanary/Canary-Framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for canary_framework-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 809a27edf6cb2a252fa5995b8dfb7a5a4fe538329454b176e9b259fdc1867744
MD5 db5fd3431f33d37d284cf0e2f62e8a89
BLAKE2b-256 d06808e57b020d63e70f0881088a685ac707e2606fa0b3dbfcc7bbf1c5205197

See more details on using hashes here.

Provenance

The following attestation bundles were made for canary_framework-0.3.0-py3-none-any.whl:

Publisher: publish.yml on HotcocoaCanary/Canary-Framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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