Skip to main content

argstart

Lets you define a "main" function to be run automatically. If that function has arguments, they'll be turned into command-line arguments.

So you can do:

from argstart import start

@start
def main(in_path: str, out_path: str, timeout: int = 500):
    ...

Instead of:

from argparse import ArgumentParser

def main(in_path: str, out_path: str, timeout: int = 500):
    ...

...

if __name__ == "__main__":
    parser = ArgumentParser()
    parser.add_argument("in_path", type=str)
    parser.add_argument("out_path", type=str)
    parser.add_argument("-t", "--timeout", type=int, default=500)
    args = parser.parse_args()

    main(args.in_path, args.out_path, args.timeout)

More details

Mostly: just write the function as you normally would, and it should work as you expect.

Use python your_file.py --help for full generated usage, like with argparse.

If specified, type annotations will be used to determine the command-line argument type.

Parses common docstring formats using docstring-parser to add command and argument descriptions.

So that all your functions get defined first, the main function is called at the end of your script - not immediately when it's defined/decorated. This is the same as if you had if __name__ == "__main__" at the bottom.

Command-line --flags also get a short acronym you can use instead, like -f.

It's command-line convention that flags are optional and positional arguments are required, so this is how arguments are translated by default:

def main(one, two, foo=1, bar=2)
# command-line: example.py [-f FOO] [-b BAR] one two

But you could force required arguments to become required flags by making them keyword-only:

def main(one, *, two, foo=1, bar=2)
# command-line: example.py -t TWO [-f FOO] [-b BAR] one

Or force optional arguments to become optional positional arguments by making them positional-only:

def main(one, two, foo=1, /, bar=2)
# command-line: example.py [-b BAR] one two [foo]

Supports *args and **kwargs:

def main(foo, *bar)
# command-line: example.py foo [bar ...]

def main(foo, **bar)
# command-line: example.py [-b [BAR ...]] foo

Finally, booleans will by default create a --toggle-flag which don't require any value after:

def main(foo=False)
# command-line: example.py [-f]
# (meaning foo defaults to False when -f flag is not given)

Metadata

Release files for argstart 0.0.3

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

Source distribution (sdist)

Source distribution for argstart 0.0.3
File Size Uploaded Provenance
argstart-0.0.3.tar.gz 4.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 9.4 kB

Release files / argstart-0.0.3.tar.gz

Download URL argstart-0.0.3.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b776503f394a00a4491cb72fab1508dcb380b7eb7ca10a9fbd08cc6eed5843bd
BLAKE2b-256 checksum
How to use checksums
30cf9bfad2f705b014e8ee15b41836fdf2ad26e6c84a1a6a5424d2e54fcdf24a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.0

Release files / argstart-0.0.3-py3-none-any.whl

Download URL argstart-0.0.3-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17c477b0e85ff69a946bb7bb23a25fe2cf477104271f3c2a91cdfbe329601124
BLAKE2b-256 checksum
How to use checksums
257c321adcea0a98f966e4c7d6921bb99b6e1e5ffc1165f8cbdcf5a01aeab75c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.0

Security for argstart 0.0.3

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.

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