Skip to main content

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 TypedDict class that serves as a contract for what the scope must contain

How it works:

  1. Recursively walks the dependency tree using scan(...)
  2. Detects all from_(...)-based dependencies
  3. Builds a TypedDict based on flattened parameter annotations
  4. 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 mypy or pyright
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fundi_scopegen-0.0.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fundi_scopegen-0.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

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

Hashes for fundi_scopegen-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b793cef16949c4f9b1184ae4c000f562104b05760c45cda6e5d681b0d3a3ee7d
MD5 2dafdc34143864a24bf5407a3bb1bb7d
BLAKE2b-256 1ca14d92fdab8f61df163608f621a352a7b1f8382d1ecf149affb3acb26b04eb

See more details on using hashes here.

File details

Details for the file fundi_scopegen-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fundi_scopegen-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 544975ba59f9ba851a0a132ff6669164e48dd46d65e78174677a92c77a88ca5b
MD5 1ea9bdf3f8e9395fb2f4e526ddac05a3
BLAKE2b-256 99e0383938068c7a08d8e2c63ff5d5de5520941dab47c1321c07618973758235

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page