Skip to main content

Fastarg

Fastarg is a command line argument parser utility that is built on Python's standard argparse library.

Installation

pip3 install fastarg

Getting started

main.py

import fastarg

app = fastarg.Fastarg(description="hello world")

@app.command()
def hello_world(name: str):
    """hello world"""
    print("hello " + name)

if __name__ == "__main__":
    app.run()

Run command:

$ python3 main.py hello_world foo

Show help text:

$ python3 main.py -h

Subcommands

Create arbitrarily large trees of subcommands.

import fastarg

app = fastarg.Fastarg(description="productivity app", prog="todo")
app2 = fastarg.Fastarg(description="to do", help="manage todos")
app3 = fastarg.Fastarg(description="user", help="manage users")
app4 = fastarg.Fastarg(description="address", help="manage addresses")

@app.command()
def hello_world(name: str):
    """hello world"""
    print("hello " + name)

@app2.command()
def create_todo(title: str, completed: bool = False):
    """create a todo"""
    print(f"create todo: {title} - {completed}")

@app2.command()
def update_todo(
    id: int = fastarg.Argument(help="the primary key of todo"), 
    completed: bool = fastarg.Option(False, help="completed status")
    ):
    """update a todo"""
    print(f"update todo: {id} - {completed}")

@app3.command()
def create_user(email: str, password: str, gold: float):
    """create a user"""
    print(f"creating {email}/{password} with {gold} gold")

@app3.command()
def delete_user(email: str):
    """delete a user"""
    print(f"deleting user {email}")

@app4.command()
def create_address(
    user_id: int, 
    address: str, 
    city: str = fastarg.Option("", help="city (e.g. Seattle)"), 
    state: str = fastarg.Option("", help="state (e.g. WA)"), 
    zip: str = fastarg.Option("", help="zip")
    ):
    """create address for user"""
    print(f"creating address for user {user_id}")
    print(f"{address} {city} {state} {zip}")


app.add_fastarg(app2, name="todo")
app.add_fastarg(app3, name="user")
app3.add_fastarg(app4, name="address")

if __name__ == "__main__":
    app.run()

Example usage

Run hello world:

$ python3 main.py hello_world foo

Show help text for todo subcommand:

$ python3 main.py todo -h

Show help text for a subcommand:

$ python3 main.py todo update_todo -h

Run create_todo subcommand:

$ python3 main.py todo create_todo "drink water"

Run create_todo with optional completed flag:

$ python3 main.py todo create_todo "drink water" --completed
$ python3 main.py todo create_todo "drink water" --no-completed

Run the nested create_address command:

$ python3 main.py user address create_address 123 "456 main st" --city bellevue --state wa --zip 98004

Arguments

Positional arguments are required. For example, the create_todo command takes a positional argument of title.

Options

Options are optional. For example, the create_address command takes an optional argument of city, state, and zip.

Subcommands in multiple files

main.py

import fastarg
import commands.todo as todo
import commands.user as user

app = fastarg.Fastarg(description="productivity app", prog="todo")

@app.command()
def hello_world(name: str):
    """hello world"""
    print("hello " + name)

app.add_fastarg(todo.app, name="todo")
app.add_fastarg(user.app, name="user")

if __name__ == "__main__":
    app.run()

commands/todo.py

import fastarg

app = fastarg.Fastarg(description="to do", help="manage todos")

@app.command()
def create_todo(title: str, completed: bool = False):
    """create a todo"""
    print(f"create todo: {title} - {completed}")

@app.command()
def update_todo(
    id: int = fastarg.Argument(help="the primary key of todo"), 
    completed: bool = fastarg.Option(False, help="completed status")
    ):
    """update a todo"""
    print(f"update todo: {id} - {completed}")

commands/user.py

import fastarg
import commands.address as address

app = fastarg.Fastarg(description="user", help="manage users")

@app.command()
def create_user(email: str, password: str, gold: float):
    """create a user"""
    print(f"creating {email}/{password} with {gold} gold")

@app.command()
def delete_user(email: str):
    """delete a user"""
    print(f"deleting user {email}")

app.add_fastarg(address.app, name="address")

Examples

https://github.com/travisluong/fastarg/tree/main/examples

Author

Travis Luong

Metadata

Release files for fastarg 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastarg 0.1.2
File Size Uploaded Provenance
fastarg-0.1.2.tar.gz 4.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fastarg 0.1.2
File Interpreter ABI Platform
fastarg-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / fastarg-0.1.2.tar.gz

Download URL fastarg-0.1.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d12c65bc665715a450d1bcc676d86d1786c7694424353f9428a6cdc907269433
BLAKE2b-256 checksum
How to use checksums
3731a54c184d57d0d9d39e712928e57e02cfeec671b308be3d7d7fab94443b59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6

Release files / fastarg-0.1.2-py3-none-any.whl

Download URL fastarg-0.1.2-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bc3b1ee30c852c6984eebf63169f8a5947adf7bb325a6217fa70103aee7453b
BLAKE2b-256 checksum
How to use checksums
142d990d4a53c493660425a3d30c8e0c5f5639ad90b550415a4c2af3e5715140
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6

Security for fastarg 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page