spec-case (Python)
In-code spec / case / why / ideal / tmp / link / rule markers + specgen, the static extractor
that compiles them into spec.json — the artifact ccr
consumes. Part of spec-case; see the repo
for concepts, the symbol-id contract, and the Go reference implementation.
Install
uv add spec-case # or: pip install spec-case
One dependency covers both ends: the markers are imported by your code at runtime,
and the same package ships the specgen console script for CI.
Use the markers
The markers are no-op decorators — at runtime each returns the function
unchanged, so importing and annotating costs nothing and never changes behavior.
They only mark functions for specgen's static (ast) extraction.
from spec_case import spec, case, why, ideal, tmp, link, rule
@spec("(tenant, name) unique; duplicate create -> ConflictError")
@case("happy_minimal", "only Name given should create", expect="201; body.id non-empty")
@case("duplicate_name", "duplicate Name", expect="409", forbid="a second row is written")
@why("database uniqueness is the cross-replica authority")
@ideal("one persistence owner replaces dual writes")
@tmp("dual-write during storage migration", until="all reads use the new store")
@link("component://docs/tenancy.md")
@rule("hot request path — watch new synchronous DB calls")
def create_notebook(req): ...
单个 spec 的 id 可省略。typing.overload 等同一 symbol 多声明场景可用
@spec("...", id="string_input") 区分;多个 spec 必须全部提供唯一 id。specgen 始终输出
统一的 {fqn?, specs[]} entry。
spec_case is zero-dependency (pure stdlib) and tiny, so taking it as a regular
runtime dependency is cheap. Because the decorators apply at import time, the
package must be importable anywhere the annotated module is imported (production
included) — it is a runtime dependency, not dev-only.
Run specgen (CI)
Compile markers into spec.json, and gate drift in CI:
uv run specgen <src-dir> -o spec.json # extract
uv run specgen <src-dir> -o spec.json --check # CI gate: exit 1 if spec.json drifted
--check compares the committed spec.json against the current markers and fails
if a symbol was renamed/removed or a marker changed. specgen parses with ast and
never imports or runs your code.
Metadata
Release files for spec-case 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spec_case-0.2.2.tar.gz | 16.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spec_case-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.6 kB
Release files / spec_case-0.2.2.tar.gz
| Download URL | spec_case-0.2.2.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
383d912eaed7064d5dcc7659fdb9aa6d86da7a2f9d36778720d22dcb2a672e5a
|
|
BLAKE2b-256 checksum How to use checksums |
382a103c8dca76c746a1852a29095f8725021ebec40cd3333bed001a675d2c25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / spec_case-0.2.2-py3-none-any.whl
| Download URL | spec_case-0.2.2-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9a4b143f7767efeae26b31c14f6b69bbbb5c8bd3ec8be85008c16ced434d945
|
|
BLAKE2b-256 checksum How to use checksums |
cab36df6dd7ee588328caf6553e062213cd1070d61a3ee8953406dc4bf330bcc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|