Typer CLI plugin for Spakky framework
Project description
Spakky Typer
Typer CLI integration plugin for Spakky Framework.
Installation
pip install spakky-typer
Or install via Spakky extras:
pip install spakky[typer]
Features
- Automatic command registration: Commands are registered from
@CliControllerclasses - Async support: Full async/await support for CLI commands
- Command grouping: Organize commands into logical groups
- Dependency injection: Services are automatically injected into controllers
- Rich integration: Leverages Typer's rich console output
Usage
Basic CLI Controller
from spakky.plugins.typer.stereotypes.cli_controller import CliController, command
@CliController("user")
class UserCliController:
def __init__(self, user_service: UserService) -> None:
self.user_service = user_service
@command("list")
async def list_users(self) -> None:
"""List all users."""
users = await self.user_service.list_all()
for user in users:
print(f"{user.id}: {user.name}")
@command("create")
async def create_user(self, name: str, email: str) -> None:
"""Create a new user."""
user = await self.user_service.create(name, email)
print(f"Created user: {user.id}")
@command("delete")
async def delete_user(self, user_id: int) -> None:
"""Delete a user by ID."""
await self.user_service.delete(user_id)
print(f"Deleted user: {user_id}")
CLI Usage
# List all users
python main.py user list
# Create a new user
python main.py user create --name "John Doe" --email "john@example.com"
# Delete a user
python main.py user delete --user-id 123
Command Options
from spakky.plugins.typer.stereotypes.cli_controller import CliController, command
@CliController("db")
class DatabaseCliController:
@command(
name="migrate",
help="Run database migrations",
short_help="Run migrations",
epilog="Use --dry-run to preview changes",
)
async def run_migrations(
self,
dry_run: bool = False,
verbose: bool = False,
) -> None:
"""Execute pending database migrations."""
if dry_run:
print("Dry run mode - no changes will be made")
# Migration logic here
@command("seed", hidden=True) # Hidden from help output
async def seed_database(self) -> None:
"""Seed database with test data."""
pass
@command("status", deprecated=True) # Mark as deprecated
async def check_status(self) -> None:
"""Check database connection status."""
pass
Accessing Typer Instance
from typer import Typer
from spakky.core.application.application import SpakkyApplication
# After application.start()
typer_app = application.container.get(Typer)
# Run the CLI
if __name__ == "__main__":
typer_app()
Application Setup
from spakky.core.application.application import SpakkyApplication
from spakky.core.application.application_context import ApplicationContext
from typer import Typer
import my_cli_module
app = (
SpakkyApplication(ApplicationContext())
.load_plugins()
.scan(my_cli_module)
.start()
)
typer_app = app.container.get(Typer)
if __name__ == "__main__":
typer_app()
Components
| Component | Description |
|---|---|
CliController |
Stereotype for CLI command groups |
command |
Decorator for CLI commands |
TyperCLIPostProcessor |
Automatic command registration post-processor |
Command Decorator Options
| Option | Type | Description |
|---|---|---|
name |
str |
Command name (defaults to method name in kebab-case) |
help |
str |
Full help text for the command |
short_help |
str |
Short help text for command list |
epilog |
str |
Text displayed after command help |
hidden |
bool |
Hide command from help output |
deprecated |
bool |
Mark command as deprecated |
no_args_is_help |
bool |
Show help when no args provided |
add_help_option |
bool |
Whether to add --help option |
rich_help_panel |
str |
Rich console help panel name |
License
MIT
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 spakky_typer-5.0.1.tar.gz.
File metadata
- Download URL: spakky_typer-5.0.1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bf39ec4e813773896d2a097f05185dade9f92f88c48ab73a3a2ad6cb51541a4
|
|
| MD5 |
05b329e1e755e7461e356012bbbe31f3
|
|
| BLAKE2b-256 |
efb11043a600a38775294e7030b7455e63bff7f0e844f718765ef0fcfaa4386e
|
Provenance
The following attestation bundles were made for spakky_typer-5.0.1.tar.gz:
Publisher:
release.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_typer-5.0.1.tar.gz -
Subject digest:
5bf39ec4e813773896d2a097f05185dade9f92f88c48ab73a3a2ad6cb51541a4 - Sigstore transparency entry: 747186360
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@8f29a1a51bb96bbc2d471d88362357d886e543ea -
Branch / Tag:
refs/heads/main - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8f29a1a51bb96bbc2d471d88362357d886e543ea -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spakky_typer-5.0.1-py3-none-any.whl.
File metadata
- Download URL: spakky_typer-5.0.1-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90a11a0e9aa5e1783789c2d8e6d937d029087ed20c6bcd0b561b16aff09d1cd0
|
|
| MD5 |
5b99aa1ec9f7a954772c59074e338c74
|
|
| BLAKE2b-256 |
a514ee22bb5a1ab4f79750acfa0a0313bf6f29066b78a966e8ae6febde729511
|
Provenance
The following attestation bundles were made for spakky_typer-5.0.1-py3-none-any.whl:
Publisher:
release.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_typer-5.0.1-py3-none-any.whl -
Subject digest:
90a11a0e9aa5e1783789c2d8e6d937d029087ed20c6bcd0b561b16aff09d1cd0 - Sigstore transparency entry: 747186362
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@8f29a1a51bb96bbc2d471d88362357d886e543ea -
Branch / Tag:
refs/heads/main - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8f29a1a51bb96bbc2d471d88362357d886e543ea -
Trigger Event:
workflow_dispatch
-
Statement type: