Skip to main content

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's operational code is in a single file. If you would like to vendor it, take the src/dykes/__init__.py and include it in your own project.

What works

  • Positional parameters
  • Store True flags
    • Two variants: type a bool or use dykes.StoreTrue
  • Store False flags
  • Count flags
  • A StrEnum of Argparse actions. dykes.Action instances can be passed to directly to argparse.add_parameter
  • Parameter help strings: provide a bare string via Annotated
  • Application description via your dataclass or NamedTuple's docstring.
  • snake_case field names converted to --kebab-case long options.

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)
    • nargs
    • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dykes-0.2.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dykes-0.2.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file dykes-0.2.0.tar.gz.

File metadata

  • Download URL: dykes-0.2.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dykes-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5bbb9474669d1b71c80cdff2e5a5dcd518580461c2585dca91538a93e3bc178a
MD5 5e36c19c048a9cd31fc673ce2ed1ad5a
BLAKE2b-256 cb25b98639d1f29061e135f763b14d2c71e1667975abc2da071cf9392578e560

See more details on using hashes here.

Provenance

The following attestation bundles were made for dykes-0.2.0.tar.gz:

Publisher: release.yml on pathunstrom/dykes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dykes-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dykes-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dykes-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3250bcda7d28b66ff7842171a650bf818653189bc162f7834f7a673ae05bc831
MD5 d315e2b8c4df83bae9366a4bad4e4e84
BLAKE2b-256 56c288a1065869420b42ca526185ddbb12fb4495502c375fa768104971c7cb68

See more details on using hashes here.

Provenance

The following attestation bundles were made for dykes-0.2.0-py3-none-any.whl:

Publisher: release.yml on pathunstrom/dykes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page