dcflags
Python package for initializing a dataclass with arguments from the command line or values from environmental variables. Meant to work as an entrypoint for applications, nothing else.
Install
dcflags is available through pip
pip install dcflags
Usage
# main.py
import dataclasses
import dcflags
@dataclasses.dataclass
class Config:
output: str
workers: int = 1
verbose: bool = False
if __name__ == "__main__":
cfg = dcflags.parse(Config)
print(cfg)
# help message
$ python main.py --help
usage: main.py [-h] [--output OUTPUT] [--workers WORKERS] [--verbose [VERBOSE]]
options:
-h, --help show this help message and exit
--output OUTPUT type: str, env: $OUTPUT
--workers WORKERS type: int, env: $WORKERS, default: 1
--verbose [VERBOSE] type: bool, env: $VERBOSE, default: False
# missing required argument
$ python main.py
usage: main.py [-h] [--output OUTPUT] [--workers WORKERS] [--verbose [VERBOSE]]
main.py: error: the following arguments are required: --output/$OUTPUT
# command line arguments
$ python main.py --output=file.txt
Config(output='file.txt', workers=1, verbose=False)
# env vars
$ OUTPUT=test.txt python main.py
Config(output='test.txt', workers=1, verbose=False)
# a bit of everything
$ OUTPUT=new.txt python main.py --verbose --workers=3
Config(output='new.txt', workers=3, verbose=True)
Metadata
Release files for dcflags 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dcflags-0.2.1.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dcflags-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.2 kB
Release files / dcflags-0.2.1.tar.gz
| Download URL | dcflags-0.2.1.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
12f41827ba49c395c76eba0ff55d35850c6e0d1eaab5b70200a8520e6175e6ff
|
|
BLAKE2b-256 checksum How to use checksums |
2e6a65ce00234329ac22623f89eaba12bf0a6d198b87fa4291ca3623172dba2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Release files / dcflags-0.2.1-py3-none-any.whl
| Download URL | dcflags-0.2.1-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc7bf6c7409b08381fae28481d5bab5b51451f38c67d3cc544f637b674803d3c
|
|
BLAKE2b-256 checksum How to use checksums |
eea3b3981a1d407fd63ab7a1e1a8c4d072b73bd747218c7c6170f91b342b78e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|