cordis_py
Cordis 的 Python 实现:面向动态系统的时空可组合性(spatiotemporal composability)元框架。
当前已实现
- Context / Fiber:插件运行时实例、生命周期状态机、依赖驱动的自动加载/卸载。
- Effect 追踪:
ctx.effect()支持 disposer、同步/异步 iterable,卸载时 LIFO 清理。 - 服务与依赖注入:
ctx.provide()、ctx.get()、ctx.set()、inject声明。 - 响应式依赖:先加载消费者再加载提供者也能自动激活;提供者卸载后消费者自动退出。
- 事件系统:
on/once/emit/parallel/serial/bail/waterfall。 - Service 基类:继承
Service并调用super().__init__(ctx, name)自动注册服务。 - Per-realm 隔离:
ctx.isolate(name, realm)可隔离同名服务。 - Intercept 配置拦截:
ctx.intercept(name, config)沿上下文链合并服务级配置(祖先条目先应用、就近覆盖),插件 inject 声明中的非空配置自动并入,Service.resolve_config()可读取合并结果。 - 同步/异步双模式:有运行事件循环时后台异步调度;无事件循环时生命周期内联驱动(
dispose_sync/restart_sync/update_sync),遇到需要事件循环的操作抛出AsyncRequiredError。 - 声明式 Loader:支持 JSON/YAML/TOML 配置、增量 reconcile、disable/enable。
- 基础 HMR:开发期针对单个 Loader Entry 的模块重载。
安装
PyPI 发布名为 cordis-python,Python 导入名仍为 cordis_py:
pip install cordis-python
快速开始
import asyncio
from cordis_py import Context, Service, inject
class Greeter(Service):
def __init__(self, ctx: Context):
super().__init__(ctx, "greeter")
def hello(self, name: str) -> str:
return f"Hello, {name}!"
@inject("greeter")
def greeter_plugin(ctx: Context, config: dict):
ctx.on("app/ready", lambda msg: print(ctx.greeter.hello(msg)))
return None
async def main():
root = Context()
await root.plugin(Greeter)
await root.plugin(greeter_plugin)
root.emit("app/ready", "Cordis")
await root.fiber.dispose()
asyncio.run(main())
同步模式
没有运行事件循环时,生命周期转换会内联完成,配合 dispose_sync 等同步 API 使用:
from cordis_py import Context, inject
@inject("greeter")
def greet_plugin(ctx: Context, config: dict):
print(ctx.greeter.hello("world"))
root = Context()
root.plugin(Greeter)
root.plugin(greet_plugin)
root.fiber.dispose_sync()
若同步调用链中遇到需要事件循环的操作(异步插件、异步效果、异步事件监听器),会抛出 AsyncRequiredError,提示改用异步 API。
文档
参考
- 论文:A Programming Paradigm for Spatiotemporal Composability
- Node.js 版:Cordis v4 / DeepSeek Harness vendor
Metadata
Release files for cordis-python 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cordis_python-0.2.0.tar.gz | 45.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cordis_python-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 72.0 kB
Release files / cordis_python-0.2.0.tar.gz
| Download URL | cordis_python-0.2.0.tar.gz |
|---|---|
| Size | 45.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1d3c6b72f10b8d6e4532f1287239f74e33f4558fa6d8fb88a8ff9cf775ca9c8
|
|
BLAKE2b-256 checksum How to use checksums |
02049b2c559032442475b5267649dda70fd4c237db9180278ccbd88e6609509f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / cordis_python-0.2.0-py3-none-any.whl
| Download URL | cordis_python-0.2.0-py3-none-any.whl |
|---|---|
| Size | 26.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
903904c05806474ed32f30c333a740932fd5766d3e96429c8a57f320a027b0a0
|
|
BLAKE2b-256 checksum How to use checksums |
d99e6d8965ddf01e3f072209bd6dcaa2ff54bb44e34d21423424707b3285486f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|