argparsenv


Nameargparsenv JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/snaeil/argparsenv
SummaryExtends python's argparser with environment variables
upload_time2024-05-17 19:49:46
maintainerNone
docs_urlNone
authorsnaeil
requires_python<4.0,>=3.10
licenseMIT
keywords cli environment arguments
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # argparsenv

This project extends python's argparse module to allow for environment variable overrides of command line arguments.

The rule for environment variable overrides is as follows:

1. If the argument is provided on the command line, the environment variable is ignored.
2. If the argument is not provided on the command line, the environment variable is used if it is set.
3. If the argument is not provided on the command line and the environment variable is not set, the default value is used.
4. If the argument is environment variable is set both on the command line and in the environment, the command line value is used.

## Installation

Stable release version:

```bash
pip install argparsenv
```

Latest development version:

```bash
pip install git+https://github.com/snaeil/argparsenv
```

## Usage

This module builds on top of python's standard library
[argparse](https://docs.python.org/3/library/argparse.html).

```python
import argparsenv

env_arg_parser = ArgumentParser()
env_arg_parser.add_argument(
    "--port",
    dest="port",
    env_var="MY_APP_DB_PORT",
    default="3306",
)
```

With this ArgumentParser instance, the port argument can be set in three ways:

1. On the command line:

```bash
python my_app.py --port 3307
```

2. As an environment variable (this can also be done by using a `.env` file):

```bash
export MY_APP_DB_PORT=3307
python my_app.py
```

3. Using the default value (here `3306`):

```bash
python my_app.py
```

## Contributing

Contributions are welcome!
For feature requests, bug reports or questions, please open an issue.
For code contributions, please open a pull request.

Please make sure to install `pre-commit` before making changes to the code (this enables
checks for code formatting, linting, etc. before committing changes):

```bash
pip install poetry
poetry install
cd path/to/argparsenv
pre-commit install
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/snaeil/argparsenv",
    "name": "argparsenv",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "cli, environment, arguments",
    "author": "snaeil",
    "author_email": "schnegel@posteo.de",
    "download_url": "https://files.pythonhosted.org/packages/a8/fb/3eb3043b6fab21e87ddff0cb5b3401c0318ef79f2d39331fb62d4dd03482/argparsenv-1.0.1.tar.gz",
    "platform": null,
    "description": "# argparsenv\n\nThis project extends python's argparse module to allow for environment variable overrides of command line arguments.\n\nThe rule for environment variable overrides is as follows:\n\n1. If the argument is provided on the command line, the environment variable is ignored.\n2. If the argument is not provided on the command line, the environment variable is used if it is set.\n3. If the argument is not provided on the command line and the environment variable is not set, the default value is used.\n4. If the argument is environment variable is set both on the command line and in the environment, the command line value is used.\n\n## Installation\n\nStable release version:\n\n```bash\npip install argparsenv\n```\n\nLatest development version:\n\n```bash\npip install git+https://github.com/snaeil/argparsenv\n```\n\n## Usage\n\nThis module builds on top of python's standard library\n[argparse](https://docs.python.org/3/library/argparse.html).\n\n```python\nimport argparsenv\n\nenv_arg_parser = ArgumentParser()\nenv_arg_parser.add_argument(\n    \"--port\",\n    dest=\"port\",\n    env_var=\"MY_APP_DB_PORT\",\n    default=\"3306\",\n)\n```\n\nWith this ArgumentParser instance, the port argument can be set in three ways:\n\n1. On the command line:\n\n```bash\npython my_app.py --port 3307\n```\n\n2. As an environment variable (this can also be done by using a `.env` file):\n\n```bash\nexport MY_APP_DB_PORT=3307\npython my_app.py\n```\n\n3. Using the default value (here `3306`):\n\n```bash\npython my_app.py\n```\n\n## Contributing\n\nContributions are welcome!\nFor feature requests, bug reports or questions, please open an issue.\nFor code contributions, please open a pull request.\n\nPlease make sure to install `pre-commit` before making changes to the code (this enables\nchecks for code formatting, linting, etc. before committing changes):\n\n```bash\npip install poetry\npoetry install\ncd path/to/argparsenv\npre-commit install\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Extends python's argparser with environment variables",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/snaeil/argparsenv",
        "Repository": "https://github.com/snaeil/argparsenv"
    },
    "split_keywords": [
        "cli",
        " environment",
        " arguments"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "93546c9bfb7f38fb5aa78da91e0ed53f0705719edbd1a6c7b911954fd90db8a1",
                "md5": "e8e0d1bd42f5f55bfcd3ad47eb83fb8f",
                "sha256": "312c6405346e5d4572975ec7fe13c2ec846930228f327da628b5c639a529947b"
            },
            "downloads": -1,
            "filename": "argparsenv-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e8e0d1bd42f5f55bfcd3ad47eb83fb8f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 4148,
            "upload_time": "2024-05-17T19:49:45",
            "upload_time_iso_8601": "2024-05-17T19:49:45.245772Z",
            "url": "https://files.pythonhosted.org/packages/93/54/6c9bfb7f38fb5aa78da91e0ed53f0705719edbd1a6c7b911954fd90db8a1/argparsenv-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8fb3eb3043b6fab21e87ddff0cb5b3401c0318ef79f2d39331fb62d4dd03482",
                "md5": "7ac2ff8ef469184ab7139533eeaac868",
                "sha256": "d8ab61b4fb2fcf0ce7c294f83ecc03276adcec78a94e1fec29a3b4538b6ff377"
            },
            "downloads": -1,
            "filename": "argparsenv-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7ac2ff8ef469184ab7139533eeaac868",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 3510,
            "upload_time": "2024-05-17T19:49:46",
            "upload_time_iso_8601": "2024-05-17T19:49:46.601897Z",
            "url": "https://files.pythonhosted.org/packages/a8/fb/3eb3043b6fab21e87ddff0cb5b3401c0318ef79f2d39331fb62d4dd03482/argparsenv-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-17 19:49:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "snaeil",
    "github_project": "argparsenv",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "argparsenv"
}
        
Elapsed time: 0.29814s