usecaseapi 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,192 @@
1
+ Metadata-Version: 2.4
2
+ Name: usecaseapi
3
+ Version: 1.0.0
4
+ Summary: FastAPI-style contracts for Python application use cases.
5
+ Project-URL: Homepage, https://github.com/Wisteria30/usecaseapi
6
+ Project-URL: Documentation, https://github.com/Wisteria30/usecaseapi/tree/main/docs
7
+ Project-URL: Repository, https://github.com/Wisteria30/usecaseapi
8
+ Project-URL: Issues, https://github.com/Wisteria30/usecaseapi/issues
9
+ Author: UseCaseAPI Contributors
10
+ Maintainer: UseCaseAPI Contributors
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: ai-agents,application-api,contracts,protocol,pydantic,usecase,workflow
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: <3.15,>=3.12
25
+ Requires-Dist: pydantic<3,>=2.12.4
26
+ Provides-Extra: dev
27
+ Requires-Dist: build>=1.3.0; extra == 'dev'
28
+ Requires-Dist: coverage>=7.12.0; extra == 'dev'
29
+ Requires-Dist: mypy>=1.18.2; extra == 'dev'
30
+ Requires-Dist: pytest>=9.0.1; extra == 'dev'
31
+ Requires-Dist: ruff>=0.14.6; extra == 'dev'
32
+ Requires-Dist: twine>=6.2.0; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # UseCaseAPI
36
+
37
+ FastAPI-style contracts for Python application use cases.
38
+
39
+ UseCaseAPI brings code-first contract clarity to same-process Python use cases. Define contracts with Python Protocols, Pydantic models, and domain exceptions, then bind them to implementations without making HTTP the boundary.
40
+
41
+ Add it when your application has internal use case nodes that need stable names, versions, input/output schemas, declared dependencies, and contract snapshots. It helps teams and AI coding agents see what can be called, what can fail, and whether a change broke an application-layer contract before that break ships.
42
+
43
+ It is inspired by the developer experience of FastAPI, but it is not a web framework. FastAPI turns Python type hints into a public HTTP API contract. UseCaseAPI turns Python type definitions into public contracts for your application layer, without forcing HTTP, RPC, serialization, or a dependency-injection container into the hot path.
44
+
45
+ UseCaseAPI is designed for applications with many internal use case nodes: workflow-like systems, ROS-like node composition, AI-agent tool surfaces, batch workers, CLIs, FastAPI/Django backends, and systems where AI-assisted coding makes accidental breaking changes easier than before.
46
+
47
+ ## What it gives you
48
+
49
+ - Code-first usecase contracts using `Protocol`, `Model`, and normal Python exceptions.
50
+ - Same-process direct calls with no JSON serialization in the hot path.
51
+ - Explicit binding from contract token to implementation factory.
52
+ - Declared usecase dependency graph with strict undeclared-call protection.
53
+ - Versioned contract identity: `name@vN`.
54
+ - Contract snapshots, conservative diffing, Markdown docs, Mermaid graph export, and CLI scaffolding.
55
+ - No DI container, no transaction manager, no HTTP/RPC runtime.
56
+
57
+ ## Install
58
+
59
+ ```bash
60
+ uv add usecaseapi
61
+ ```
62
+
63
+ For local development:
64
+
65
+ ```bash
66
+ uv sync --extra dev
67
+ uv run pytest
68
+ uv run mypy
69
+ uv run ruff check .
70
+ ```
71
+
72
+ Python support: 3.12, 3.13, and 3.14. Pydantic v2 is required.
73
+
74
+ ## Quick example
75
+
76
+ Define a contract:
77
+
78
+ ```python
79
+ from __future__ import annotations
80
+
81
+ from typing import ClassVar, Literal, Protocol
82
+
83
+ from usecaseapi import Contract, Model, UseCase, UseCaseError, UseCaseRef, define_usecase
84
+
85
+
86
+ class Input(Model):
87
+ user_id: str
88
+ sku_id: str
89
+ quantity: int
90
+
91
+
92
+ class Output(Model):
93
+ order_id: str
94
+ status: Literal["accepted"]
95
+
96
+
97
+ class PlaceOrderError(UseCaseError):
98
+ code: ClassVar[str] = "orders.place_order"
99
+
100
+
101
+ class InventoryShortage(PlaceOrderError):
102
+ code: ClassVar[str] = "orders.place_order.inventory_shortage"
103
+
104
+ def __init__(self, *, sku_id: str, requested: int, available: int) -> None:
105
+ self.sku_id = sku_id
106
+ self.requested = requested
107
+ self.available = available
108
+ super().__init__(
109
+ f"inventory shortage: sku_id={sku_id}, requested={requested}, available={available}"
110
+ )
111
+
112
+
113
+ class PlaceOrder(UseCase[Input, Output], Protocol):
114
+ async def __call__(self, input: Input, /) -> Output:
115
+ ...
116
+
117
+
118
+ PLACE_ORDER: UseCaseRef[Input, Output] = define_usecase(
119
+ PlaceOrder,
120
+ Contract(
121
+ name="orders.place_order",
122
+ version=1,
123
+ input=Input,
124
+ output=Output,
125
+ raises=(PlaceOrderError,),
126
+ known_errors=(InventoryShortage,),
127
+ ),
128
+ )
129
+ ```
130
+
131
+ Implement it:
132
+
133
+ ```python
134
+ from app.contracts.orders.place_order.v1 import Input, Output, PlaceOrder
135
+
136
+
137
+ class PlaceOrderImpl:
138
+ async def __call__(self, input: Input, /) -> Output:
139
+ return Output(order_id="ord_123", status="accepted")
140
+
141
+
142
+ _impl: PlaceOrder = PlaceOrderImpl()
143
+ ```
144
+
145
+ Bind and call it:
146
+
147
+ ```python
148
+ from dataclasses import dataclass
149
+
150
+ from usecaseapi import UseCaseAPI
151
+
152
+
153
+ @dataclass(frozen=True)
154
+ class AppContext:
155
+ tenant_id: str
156
+
157
+
158
+ usecases = UseCaseAPI[AppContext]()
159
+ usecases.bind(PLACE_ORDER, lambda caller: PlaceOrderImpl())
160
+
161
+ output = await usecases.caller(AppContext(tenant_id="t1")).call(PLACE_ORDER, input)
162
+ ```
163
+
164
+ ## Scaffold
165
+
166
+ ```bash
167
+ usecaseapi scaffold orders.place_order --version 1
168
+
169
+ # Create the next major contract version by scanning app/contracts/orders/place_order/v*.py
170
+ usecaseapi scaffold orders.place_order --next
171
+ ```
172
+
173
+ This creates:
174
+
175
+ ```text
176
+ app/contracts/orders/place_order/v1.py
177
+ app/usecases/orders/place_order.py
178
+ tests/test_orders_place_order_v1.py
179
+ ```
180
+
181
+ ## Why not just write classes yourself?
182
+
183
+ You can, and for small projects you should. UseCaseAPI becomes useful when you have many internal nodes and you need to know:
184
+
185
+ - which functions are public application-layer contracts;
186
+ - which version each caller depends on;
187
+ - which usecase dependencies are allowed;
188
+ - which domain exceptions are part of the contract;
189
+ - whether AI-assisted changes silently broke a stable contract;
190
+ - what the application graph looks like.
191
+
192
+ UseCaseAPI is a small runtime plus guardrails for that problem.
@@ -0,0 +1,15 @@
1
+ usecaseapi/__init__.py,sha256=GysDGjkSd2_hnFsFfr3nDXiTrloeb7a6_WMffDOPePs,1306
2
+ usecaseapi/api.py,sha256=pa_AVvYgdwnZpxFDwUDpIZjpMaK-woLclJ2zbD3XaGo,11240
3
+ usecaseapi/cli.py,sha256=vTmVfVoixGw6Ez7g-wCOsTClih3dcssZ3A8nDhDU93w,6687
4
+ usecaseapi/contracts.py,sha256=f381PMoz5kwrDoX_4gABTlKr-Eg76TV83nxtK1-GiC0,3750
5
+ usecaseapi/docs.py,sha256=vWeJMNJGFp5jnfs8tf0m_ZYUk3Ed7sNc3MmEPNQUUko,3625
6
+ usecaseapi/errors.py,sha256=MWRuru7QHHtjZ91baUw9mbvvw_Oor0n0ABKslGhvP8s,2661
7
+ usecaseapi/model.py,sha256=2TbrDmfJoT4_mE-CVNl_PscB-noJkzgg6EYU4M6pVpM,427
8
+ usecaseapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ usecaseapi/scaffold.py,sha256=yg2tXuCgqoHl_t3Gi6EAxDrrEgTrjQ726NZUxMUzxsU,9376
10
+ usecaseapi/snapshot.py,sha256=1cP8JlM8aDmi1HBnvGDiN0_BIbbN_TmNPTGONSh3jvk,6435
11
+ usecaseapi-1.0.0.dist-info/METADATA,sha256=iBMkZbGy3L8gt9Aa7MpxDoTqamUmmjA93gt38Avlhgs,6268
12
+ usecaseapi-1.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
13
+ usecaseapi-1.0.0.dist-info/entry_points.txt,sha256=2Yh2Foj8nShIccwJnVlIB93r-HuTfGxuXoALJ-eMHDU,51
14
+ usecaseapi-1.0.0.dist-info/licenses/LICENSE,sha256=TI-kEZHjWgCoERF8Hdvh5ErMom2G9cJSVwvWw-9B2uo,1080
15
+ usecaseapi-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ usecaseapi = usecaseapi.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 UseCaseAPI Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.