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
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 Injection —
deps=[DBService]auto-injected asself.db_service - Config Management —
@config+ pydantic-settings, auto-reads.envand env vars - Lifecycle Hooks —
@on_init/@on_start/@on_end, sync/async adaptive - Web Integration —
WebCanaryfor one-click FastAPI + Uvicorn - Context System — parent chain delegates config and dependency resolution upward
- Type Safety —
ctx.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
- 💬 Discussions
- 🐛 Issues
- 📖 Docs
Contributing
See CONTRIBUTING.md.
License
Apache 2.0 · Copyright 2026 张文博 (Canary)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file canary_framework-0.2.1.tar.gz.
File metadata
- Download URL: canary_framework-0.2.1.tar.gz
- Upload date:
- Size: 68.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0120ea99972ca83cede813dab1878f89b0d474a57547a72079c077341d7b1908
|
|
| MD5 |
5f551488b49263c38b37bf55a2bc8532
|
|
| BLAKE2b-256 |
539d2e3b8882e8f347d5a85e8724fe3182187826a11a3ecdf57f053d4b4f70df
|
Provenance
The following attestation bundles were made for canary_framework-0.2.1.tar.gz:
Publisher:
publish.yml on HotcocoaCanary/Canary-Framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
canary_framework-0.2.1.tar.gz -
Subject digest:
0120ea99972ca83cede813dab1878f89b0d474a57547a72079c077341d7b1908 - Sigstore transparency entry: 1631703091
- Sigstore integration time:
-
Permalink:
HotcocoaCanary/Canary-Framework@a4911876de3872c776c4a32b9a4567bea83d1145 -
Branch / Tag:
refs/heads/releases/v0.2.1 - Owner: https://github.com/HotcocoaCanary
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a4911876de3872c776c4a32b9a4567bea83d1145 -
Trigger Event:
push
-
Statement type:
File details
Details for the file canary_framework-0.2.1-py3-none-any.whl.
File metadata
- Download URL: canary_framework-0.2.1-py3-none-any.whl
- Upload date:
- Size: 52.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
577dde0a5548a1fbe53d2b43867746d09af9fb2c2cdf94342267f65627d2941a
|
|
| MD5 |
20d0d07cc3e7e4a36d7ae9d6c92a831c
|
|
| BLAKE2b-256 |
449e16eede5467ec87e261e6886a0985cc051333b2f3f9ecbe965dda162454b4
|
Provenance
The following attestation bundles were made for canary_framework-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on HotcocoaCanary/Canary-Framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
canary_framework-0.2.1-py3-none-any.whl -
Subject digest:
577dde0a5548a1fbe53d2b43867746d09af9fb2c2cdf94342267f65627d2941a - Sigstore transparency entry: 1631703098
- Sigstore integration time:
-
Permalink:
HotcocoaCanary/Canary-Framework@a4911876de3872c776c4a32b9a4567bea83d1145 -
Branch / Tag:
refs/heads/releases/v0.2.1 - Owner: https://github.com/HotcocoaCanary
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a4911876de3872c776c4a32b9a4567bea83d1145 -
Trigger Event:
push
-
Statement type: