simpcli3
A Python3 module for turning functions into cmd-line programs trivially.
Examples
Non-dataclass (simple function) example
from simpcli3 import CliApp
from typing import List
def myls(paths: List[str], exclude: List[str]=[], mystr: str=None, follow_symlinks: bool=False):
print(f"Received args: {paths}\n")
for path in paths:
print(path)
if __name__ == "__main__":
CliApp(myls).run()
More advanced Example
This example actually uses a dataclass argument rather than a collection of arguments of primitive types.
from dataclasses import dataclass, field
from enum import Enum
from typing import List
class PrintFormat(Enum):
LINE_PER_ENTRY = 1
PRETTY = 2
@dataclass
class ListDirectoryArgs:
paths: List[str] = field(metadata=dict(positional=True))
exclude: List[str] = field(default_factory=list)
print_format: PrintFormat = PrintFormat.PRETTY
follow_symlinks: bool = True
def myls(lsargs: ListDirectoryArgs):
print(f"Received args: {lsargs}\n")
for path in lsargs.paths:
print(path)
if __name__ == "__main__":
from simpcli3 import CliApp
CliApp(myls).run()
Looking Forward
It would be nice to also be able to parse JSON / TOML config files into dataclasses, rather than having ever-growing cmd-line args.
Prior Art
And why I didn't use it.
For argparse_dataclasses and argparse_dataclass reasons, see Improvements.
SimpleParsing (pip install simple_parsing). Different goals and approaches in terms of simplicity. For one, we don't depend on numpy.
Improvements over projects based on
Modifications made from "argparse_dataclass": 2. "positional" metadata arg as I think that's more intuitive than passing "args" directly. 3. If type is enum, choices automatically specified, default given as string (kind of like "argparse_dataclasses" package, but with cleaner impl IMO) 4. Better handling of bools (especially ones which default to True). 5. Wrapper over field (idea lifted from argparse_dataclasses)
Metadata
Release files for simpcli3 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simpcli3-0.0.3.tar.gz | 13.1 kB | Without provenance | Details for simpcli3-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simpcli3-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for simpcli3-0.0.3-py3-none-any.whl |
Total release size: 26.5 kB
Release files / simpcli3-0.0.3.tar.gz
| Download URL | simpcli3-0.0.3.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b011e5494327413f993bd07908d45f8cb498ea23fff3e7c13bdb94f20a4bc874
|
|
BLAKE2b-256 checksum How to use checksums |
cdb856439a21c3d7ace70a1d8b0ea281a5cdf1983ad78ce7264d18245e68e53b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5
|
Release files / simpcli3-0.0.3-py3-none-any.whl
| Download URL | simpcli3-0.0.3-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d7677af7fa9ab55ef7353a850c1d184332310897225e7a1acd9c3212cdd41f32
|
|
BLAKE2b-256 checksum How to use checksums |
1db1f736204b2a3315e698ac35109ddcea89da96549c20d559ae915ecfa4e670
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5
|
Security for simpcli3 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.