A tiny declarative Argparse wrapper.
Project description
Do You Know Every Selection?
dykes helps you get a handle on your tools.
It uses typing.NamedTuples or dataclasses to declaratively set up your argument parser and then returns an instance of your argument class.
An example usage, in example_application.py
from dataclasses import dataclass
from pathlib import Path
from typing import Annotated
import dykes
@dataclass
class ExampleApplication:
path: Annotated[Path, "The paths to operate on."]
dry_run: bool
prompt: dykes.StoreFalse
verbosity: dykes.Count
if __name__ == "__main__":
arguments = dykes.parse_args(ExampleApplication)
print(arguments)
Use this from the command line:
python example_application.py ~ -d -vv
And the output looks like:
ExampleApplication(path=Path('~'), dry_run=True, prompt=True, verbosity=2)
Inlining dykes
While dykes is packaged to be used with pip, it is self-contained and uses relative imports for its own code.
If you would like to vendor it, take the files under src/dykes/ and include it in your own project.
What works
- Positional parameters
- Store True flags
- Two variants: type a
boolor usedykes.StoreTrue
- Two variants: type a
- Store False flags
- Count flags
- A StrEnum of Argparse actions.
dykes.Actioninstances can be passed to directly toargparse.add_parameter - Parameter help strings: provide a bare string via Annotated
- Application description via your
dataclassorNamedTuple's docstring. snake_casefield names converted to--kebab-caselong options.- Number of Args
- Implicitly with
arg: list[T] - explicitly via
arg: Annotated[list[T], dykes.options.NArgs("+")] - Explicit can use positional arguments with a default factory via
dataclasses.fieldas well.
- Implicitly with
What works but is underwhelming
- Parameter defaults. (positional parameters can't use them, and the other supported fields have good ones.)
Coming Soon
- More actions
- Store Const
- Append
- Append Const
- Extend
- Version
- More Options
- Defining custom flags (currently derived from names)
- const
- choices
- required
- deprecated
- Proper documentation
Coming Maybe
- Application framework based on
__call__ - Subcommands
Isn't That Name Insensitive?
Author and maintainer here: I am a transgender lesbian and I find it funny. If you don't want that word in your project, that's fine! Please see instructions above on how to inline the project. Feel free to rename it.
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 dykes-0.4.0.tar.gz.
File metadata
- Download URL: dykes-0.4.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
108c7ea45383563a59766d98983b356f0c4ebf329c1660cff9ca7b8c71d802c5
|
|
| MD5 |
008a89cc9b7f3eb3f1b96cb9296e0f60
|
|
| BLAKE2b-256 |
b6b6c1d127eef716af6af3d0b2b01d931cbf3d81683b4d1b1d2ab734cd64e5cc
|
Provenance
The following attestation bundles were made for dykes-0.4.0.tar.gz:
Publisher:
release.yml on pathunstrom/dykes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dykes-0.4.0.tar.gz -
Subject digest:
108c7ea45383563a59766d98983b356f0c4ebf329c1660cff9ca7b8c71d802c5 - Sigstore transparency entry: 264419281
- Sigstore integration time:
-
Permalink:
pathunstrom/dykes@acefea61b83a80bad8826ed095a38ebdc21511dd -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/pathunstrom
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@acefea61b83a80bad8826ed095a38ebdc21511dd -
Trigger Event:
release
-
Statement type:
File details
Details for the file dykes-0.4.0-py3-none-any.whl.
File metadata
- Download URL: dykes-0.4.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b68866db7ed108f9112fa894b23531b5ea5ef6af32cd706009d9e35faaec6f35
|
|
| MD5 |
0e4354feae7fc85b9b24d349b5edd873
|
|
| BLAKE2b-256 |
eeb54f14bf8e64817c03b720b7fab1137213c0c4988d8df05fb6894d26d7360e
|
Provenance
The following attestation bundles were made for dykes-0.4.0-py3-none-any.whl:
Publisher:
release.yml on pathunstrom/dykes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dykes-0.4.0-py3-none-any.whl -
Subject digest:
b68866db7ed108f9112fa894b23531b5ea5ef6af32cd706009d9e35faaec6f35 - Sigstore transparency entry: 264419283
- Sigstore integration time:
-
Permalink:
pathunstrom/dykes@acefea61b83a80bad8826ed095a38ebdc21511dd -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/pathunstrom
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@acefea61b83a80bad8826ed095a38ebdc21511dd -
Trigger Event:
release
-
Statement type: