dcflags


Namedcflags JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/adriansahlman/dcflags
SummaryDataclass fields as cmd args and env vars
upload_time2023-10-26 16:50:25
maintainer
docs_urlNone
authorAdrian Sahlman
requires_python>=3.5
licenseMIT
keywords parse arguments cmd command dataclass env environmental dcflags
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dcflags

Python package for initializing a dataclass with values from the command line and from environmental variables.

## Install

dcflags is available through pip
```shell
pip install dcflags
```

## Usage
```python
# 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)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/adriansahlman/dcflags",
    "name": "dcflags",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "parse arguments cmd command dataclass env environmental dcflags",
    "author": "Adrian Sahlman",
    "author_email": "adrian.sahlman@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/02/6b/767e2fc388d183b37b38952989ebb2c4c78d7a02bf506f61680fcc80af8a/dcflags-0.1.0.tar.gz",
    "platform": null,
    "description": "# dcflags\n\nPython package for initializing a dataclass with values from the command line and from environmental variables.\n\n## Install\n\ndcflags is available through pip\n```shell\npip install dcflags\n```\n\n## Usage\n```python\n# main.py\n\nimport dataclasses\nimport dcflags\n\n\n@dataclasses.dataclass\nclass Config:\n    output: str\n    workers: int = 1\n    verbose: bool = False\n\n\nif __name__ == \"__main__\":\n    cfg = dcflags.parse(Config)\n    print(cfg)\n```\n```\n# help message\n$ python main.py --help\nusage: main.py [-h] [--output OUTPUT] [--workers WORKERS] [--verbose [VERBOSE]]\n\noptions:\n  -h, --help           show this help message and exit\n  --output OUTPUT      type: str, env: $OUTPUT\n  --workers WORKERS    type: int, env: $WORKERS, default: 1\n  --verbose [VERBOSE]  type: bool, env: $VERBOSE, default: False\n\n# missing required argument\n$ python main.py\nusage: main.py [-h] [--output OUTPUT] [--workers WORKERS] [--verbose [VERBOSE]]\nmain.py: error: the following arguments are required: --output/$OUTPUT\n\n# command line arguments\n$ python main.py --output=file.txt\nConfig(output='file.txt', workers=1, verbose=False)\n\n# env vars\n$ OUTPUT=test.txt python main.py\nConfig(output='test.txt', workers=1, verbose=False)\n\n# a bit of everything\n$ OUTPUT=new.txt python main.py --verbose --workers=3\nConfig(output='new.txt', workers=3, verbose=True)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Dataclass fields as cmd args and env vars",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/adriansahlman/dcflags"
    },
    "split_keywords": [
        "parse",
        "arguments",
        "cmd",
        "command",
        "dataclass",
        "env",
        "environmental",
        "dcflags"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ff5de7c1fed78aabf9d67c6ccdac1b01502cdf5a347c9e78802dcb5d0758ecf",
                "md5": "6cbaf60aee097ffeda229902fe1483a2",
                "sha256": "bd7833da4106e96490b309c9419b7a62e5158050640b207a497c516d1c1a4247"
            },
            "downloads": -1,
            "filename": "dcflags-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6cbaf60aee097ffeda229902fe1483a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 5191,
            "upload_time": "2023-10-26T16:50:23",
            "upload_time_iso_8601": "2023-10-26T16:50:23.339480Z",
            "url": "https://files.pythonhosted.org/packages/8f/f5/de7c1fed78aabf9d67c6ccdac1b01502cdf5a347c9e78802dcb5d0758ecf/dcflags-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "026b767e2fc388d183b37b38952989ebb2c4c78d7a02bf506f61680fcc80af8a",
                "md5": "81c2c99998cf2b1b77604ec386069cd4",
                "sha256": "56216612e9557aa2ca1cc486c4f119b3b10a593e65866a37571ba182af419570"
            },
            "downloads": -1,
            "filename": "dcflags-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "81c2c99998cf2b1b77604ec386069cd4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 4874,
            "upload_time": "2023-10-26T16:50:25",
            "upload_time_iso_8601": "2023-10-26T16:50:25.066298Z",
            "url": "https://files.pythonhosted.org/packages/02/6b/767e2fc388d183b37b38952989ebb2c4c78d7a02bf506f61680fcc80af8a/dcflags-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-26 16:50:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "adriansahlman",
    "github_project": "dcflags",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dcflags"
}
        
Elapsed time: 0.53827s