Skip to main content

Arrrgs PyPI version Quality assurance

Logo

The library for easily writing feature-rich Python scripts. Uses the built-in argparse module for parsing.

  • Simple API
  • Automatic async support
  • Small size

Installing

pip install arrrgs

Usage

Basic

To declare a command, write a function and add the command decorator to it. To start command processing, call the function run.

from arrrgs import command, run
from os import getlogin

@command()
def hello():
    """Prints hello message to current user"""
    print(f"Hello, {getlogin()}")

if __name__ == "__main__":
    run()

Arrrgs will process the command and show the user the result. The help message will be generated from the function documentation.

python examples/basic.py hello --help
# usage: basic.py hello [-h]

# Prints hello message to current user

# optional arguments:
#   -h, --help  show this help message and exit

Custom command absence handler

Use the root_command decorator to set up a no-command handler. The same rules apply to this function as to normal command handlers except that it cannot have its own arguments.

from arrrgs import run, root_command

@root_command()
def print_hello():
    """Prints hello message to current user"""
    print("Hello, user")

if __name__ == "__main__":
    run()

Arguments

To add arguments for command you need to pass their description to the decorator arguments. If you need global arguments, pass them to global_args function. The available parameters of arg are the same as for add_argument in argparse.

from arrrgs import command, arg, run, global_args

global_args(
    arg("--rage", "-r", action='store_true', help="Rage mod")
)

@command(
    arg("name", help="User name")
)
def hello(args):
    """Prints hello message to current user"""
    user_name = args.name
    if args.rage:
        user_name = user_name.upper()
    print(f"Hello, {user_name}")

if __name__ == "__main__":
    run()

Context

Sometimes all the teams in an application need a common entity that they interact with. Commands have a context for that. The context value is set when the function run is called.

from arrrgs import command, run

class User:
    def __init__(self, name):
        self._name = name

    def get_name(self):
        """Returns user name"""
        return self._name

@command()
def hello(_, context):
    """Prints hello message to current user"""
    print(f"Hello, {context.get_name()}")

if __name__ == "__main__":
    user = User("Mikhael")
    run(user)

Async

To execute the command in an asynchronous context, simply add the async keyword in the function declaration.

@command()
async def hello():
    """Prints hello message to current user"""
    print("Hello, async user")

Custom command name

A situation may arise where you have to name a command after a built-in function or type, e.g. list. To specify a command name other than the function name, use the name parameter.

@command(name="list")
def list_numbers():
    """Prints list of numbers"""
    print("1, 2, 3")

Metadata

Release files for arrrgs 3.1.0

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

Source distribution (sdist)

Source distribution for arrrgs 3.1.0
File Size Uploaded Provenance Actions
arrrgs-3.1.0.tar.gz 24.9 kB Without provenance Details for arrrgs-3.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 31.2 kB

Release files / arrrgs-3.1.0.tar.gz

Download URL arrrgs-3.1.0.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
604c490dcc251963291356ab5f5adcf311ae299e4657a54a38ce390e721c1046
BLAKE2b-256 checksum
How to use checksums
eefb872361c95912b9a764b238157d0c5962003b46bf7525ebebd4d0f6e5858b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Release files / arrrgs-3.1.0-py3-none-any.whl

Download URL arrrgs-3.1.0-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a9f763654569f4c6fd8690b07680a7a5e767860c7299b3fd375faf763ba08c9
BLAKE2b-256 checksum
How to use checksums
6263b4ae9a7c62e87f3961700bfa7bb521ed97a228816d13f9409584d2894301
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Security for arrrgs 3.1.0

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