Dependency injection for typer
Project description
typer-injector
typer-injector adds FastAPI-style dependency injection to Typer.
Table of Contents
Installation
pip install typer-injector
Usage
Example:
import socket
from typing import Annotated, TypeAlias
import typer
from typer_injector import Depends, InjectingTyper
app = InjectingTyper()
def address_dependency(
host: Annotated[str, typer.Option()],
port: Annotated[int, typer.Option()],
) -> tuple[str, int]:
return host, port
Address: TypeAlias = Annotated[tuple[str, int], Depends(address_dependency)]
@app.command()
def send_message(message: str, address: Address) -> None:
"""Send a message to the specified address."""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect(address)
sock.send(message.encode())
@app.command()
def receive_message(address: Address) -> None:
"""Listen for a message at the specified address."""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.bind(address)
sock.listen(1)
conn, _ = sock.accept()
with conn:
data = conn.recv(1024)
print(data.decode())
if __name__ == '__main__':
app()
License
typer-injector is distributed under the terms of the MIT license.
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
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 typer_injector-0.2.1.tar.gz.
File metadata
- Download URL: typer_injector-0.2.1.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b02511ba1434f8527fd7cad0f8901fe9af2b487129fe67b4466a29c0bd6d6ae
|
|
| MD5 |
8b49b001d6fabaee965ec56f10d03ab0
|
|
| BLAKE2b-256 |
e4b8ea06b54357d86057af236e18d190c38ec9896017be65530efdc41e9aee27
|
Provenance
The following attestation bundles were made for typer_injector-0.2.1.tar.gz:
Publisher:
release.yml on BenjyWiener/typer-injector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typer_injector-0.2.1.tar.gz -
Subject digest:
2b02511ba1434f8527fd7cad0f8901fe9af2b487129fe67b4466a29c0bd6d6ae - Sigstore transparency entry: 1390560942
- Sigstore integration time:
-
Permalink:
BenjyWiener/typer-injector@0786955757b9aa28c4fc86fc2f685ad2e1dbb91a -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/BenjyWiener
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0786955757b9aa28c4fc86fc2f685ad2e1dbb91a -
Trigger Event:
push
-
Statement type:
File details
Details for the file typer_injector-0.2.1-py3-none-any.whl.
File metadata
- Download URL: typer_injector-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43f1eb49e65ad4291fac19178fb394da74e389e330c11fb14ea9a4c1436c6a99
|
|
| MD5 |
bb2da47f5f3af4349146d788e19f76d7
|
|
| BLAKE2b-256 |
f40d0a3f057575e5b6dbccb215c78d18656827fa2217bbc249a70552b6e9d13f
|
Provenance
The following attestation bundles were made for typer_injector-0.2.1-py3-none-any.whl:
Publisher:
release.yml on BenjyWiener/typer-injector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typer_injector-0.2.1-py3-none-any.whl -
Subject digest:
43f1eb49e65ad4291fac19178fb394da74e389e330c11fb14ea9a4c1436c6a99 - Sigstore transparency entry: 1390560951
- Sigstore integration time:
-
Permalink:
BenjyWiener/typer-injector@0786955757b9aa28c4fc86fc2f685ad2e1dbb91a -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/BenjyWiener
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0786955757b9aa28c4fc86fc2f685ad2e1dbb91a -
Trigger Event:
push
-
Statement type: