Generate scope type that can be used to safely inject values using FunDIs scope values resolution
Project description
# fundi-scopegen
Type-safe scope declaration generator for fundi dependency injection
fundi-codegen generates TypedDict classes that describe the expected scope structure for fundi-based functions.
This allows you to call inject(scope, scan(...), stack) with full type checking, autocomplete, and IDE support — no plugins or runtime introspection needed.
HOW IT WORKS
fundi-scopegen analyzes a function (and its dependency tree) via scan(...), extracts all from_(...) and outputs:
- a full list of all keys required in the
scope - expected types (supporting
FromType,Literal,Optional,Union,Annotated,Parameter, etc.) - import statements for required symbols
- a
TypedDictclass that serves as a contract for what thescopemust contain
How it works:
- Recursively walks the dependency tree using
scan(...) - Detects all
from_(...)-based dependencies - Builds a
TypedDictbased on flattened parameter annotations - Outputs a ready-to-use Python type declaration
USAGE EXAMPLES
Generate a scope for a function
fundi-scopegen play.application
Output:
from typing import Any, TypedDict, NotRequired
from fundi import FromType
from fundi.types import Parameter
class ApplicationScope(TypedDict):
parameter: NotRequired[FromType[None | Parameter]]
app_name: NotRequired[str | None]
some: NotRequired[str]
username: Any
With terminal color (for CLI readability)
fundi-scopegen play.application --colored
Without imports
fundi-scopegen play.application --no-imports
Output:
class ApplicationScope(TypedDict):
parameter: NotRequired[FromType[None | Parameter]]
app_name: NotRequired[str | None]
some: NotRequired[str]
username: Any
Using it in code
from contextlib import ExitStack
from fundi import inject, scan
from play import application
from scopes import ApplicationScope
scope: ApplicationScope = {
"username": "kuyugama",
"some": "waffel",
}
with ExitStack() as stack:
result = inject(scope, scan(application), stack)
Benefits
- Full IDE autocomplete
- Type-checking with
mypyorpyright - Lightweight: no runtime cost or decorators
- Easy to regenerate on dependency changes
🐾 Stop guessing your scope shape. Generate it once, and type it forever 😼
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 fundi_scopegen-0.0.1.tar.gz.
File metadata
- Download URL: fundi_scopegen-0.0.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b793cef16949c4f9b1184ae4c000f562104b05760c45cda6e5d681b0d3a3ee7d
|
|
| MD5 |
2dafdc34143864a24bf5407a3bb1bb7d
|
|
| BLAKE2b-256 |
1ca14d92fdab8f61df163608f621a352a7b1f8382d1ecf149affb3acb26b04eb
|
File details
Details for the file fundi_scopegen-0.0.1-py3-none-any.whl.
File metadata
- Download URL: fundi_scopegen-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
544975ba59f9ba851a0a132ff6669164e48dd46d65e78174677a92c77a88ca5b
|
|
| MD5 |
1ea9bdf3f8e9395fb2f4e526ddac05a3
|
|
| BLAKE2b-256 |
99e0383938068c7a08d8e2c63ff5d5de5520941dab47c1321c07618973758235
|