passarg


Namepassarg JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryOpenSSL-style password argument handling.
upload_time2024-08-03 07:14:45
maintainerNone
docs_urlNone
authorNone
requires_python<4,>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # passarg: OpenSSL password/-phrase argument

The passarg ("password argument") module implements
OpenSSL-style password/passphrase argument handling.

# Quickstart

```python
from argparse import ArgumentParser

import passarg

parser = ArgumentParser()
parser.add_argument('--pass-in', metavar='SPEC', default='env:MY_PASS_IN')
parser.add_argument('--pass-out', metavar='SPEC', default='env:MY_PASS_OUT')
args = parser.parse_args()

with passarg.reader() as read_passarg:
    pass_in = read_passarg(args.pass_in)
    pass_out = read_passarg(args.pass_out)
```

The program above then by default reads the input/output passphrases
from the environment variables `${MY_PASS_IN}` and `${MY_PASS_OUT}`;
if run with `--pass-in file:dec-pass.txt --pass-out stdin`,
then it reads the input/output passphrases
from the file `dec-pass.txt` and the standard input respectively.

# Passphrase Argument Syntax

passarg supports the following OpenSSL-compatible arguments
([openssl-passphrase-options(1)]):

* **pass**:*password*

  The actual password is *password*.
  Since the password is visible to utilities (like 'ps' under Unix)
  this form should only be used where security is not important.

* **env**:*var*

  Obtain the password from the environment variable *var*.
  Since the environment of other processes is visible on certain platforms
  (e.g. ps under certain Unix OSes)
  this option should be used with caution.

* **file**:*pathname*

  Reads the password from the specified file *pathname*,
  which can be a regular file, device, or named pipe.
  Only the first line, up to the newline character, is read from the stream.

  If the same *pathname* argument is supplied
  to both **-passin** and **-passout** arguments,
  the first line will be used for the input password,
  and the next line will be used for the output password.

* **fd**:*number*

  Reads the password from the file descriptor *number*.
  This can be useful for sending data via a pipe, for example.
  The same line handling as described for **file:** applies
  to passwords read from file descriptors.

  **fd:** is not supported on Windows.

* **stdin**

  Reads the password from standard input.
  The same line handling as described for **file:** applies
  to passwords read from standard input.

passarg also supports the following non-OpenSSL extensions:

* **prompt**[:*text*]

  Prompts the password using Python [getpass()].
  If *text* is given, it is used as the prompt.
  Otherwise, the getpass default (`Password: `) is used.

* **op**:[//*Vault*/]*TitleOrID*[/*field*]

  Fetches the given item using the [1Password CLI].
  *Vault* is optional and defaults to `Private` or `Employee`;
  *field* is also optional and defaults to `password`.

# .env ("dotenv") File Support

passarg can be combined with [python-dotenv] to add support for dotenv files.
Simply call load_dotenv before entering the `passarg.reader()` context:

```python
from argparse import ArgumentParser

import dotenv

import passarg

parser = ArgumentParser()
parser.add_argument('--api-key', metavar='SPEC', default='env:MY_API_KEY')
parser.add_argument('--env-file', metavar='PATH', default='.env')
args = parser.parse_args()

dotenv.load_dotenv(args.env_file)

with passarg.reader() as read_passarg:
    api_key = read_passarg(args.api_key)
```

Then it can be run in the directory with an `.env` file like:

```
MY_API_KEY=MySuperSecretKeyOmigod
```

# Passargs Sharing Same File-like Source

As explained in [Passphrase Argument Syntax](#passphrase-argument-syntax) above,
multiple passphrase arguments can share the same file-like source,
with each source reading one line from the source.

The order of calls to `read_passarg()` matters, and should be documented.
For example, the [Quickstart example](#quickstart) above
reads `--pass-in` first then `--pass-out`,
implementing the same input-password-first ordering as with OpenSSL.

[python-dotenv]: https://pypi.org/project/python-dotenv/
[openssl-passphrase-options(1)]: https://docs.openssl.org/3.3/man1/openssl-passphrase-options/
[getpass()]: https://docs.python.org/3/library/getpass.html#getpass.getpass
[1Password CLI]: https://developer.1password.com/docs/cli/reference/management-commands/item#item-get

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "passarg",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Eugene Kim <ab@astral.blue>",
    "download_url": "https://files.pythonhosted.org/packages/31/02/c287bdd5328a6078ff92b6b841c0358e7c9b4794641b434eb423099a1088/passarg-0.1.0.tar.gz",
    "platform": null,
    "description": "# passarg: OpenSSL password/-phrase argument\n\nThe passarg (\"password argument\") module implements\nOpenSSL-style password/passphrase argument handling.\n\n# Quickstart\n\n```python\nfrom argparse import ArgumentParser\n\nimport passarg\n\nparser = ArgumentParser()\nparser.add_argument('--pass-in', metavar='SPEC', default='env:MY_PASS_IN')\nparser.add_argument('--pass-out', metavar='SPEC', default='env:MY_PASS_OUT')\nargs = parser.parse_args()\n\nwith passarg.reader() as read_passarg:\n    pass_in = read_passarg(args.pass_in)\n    pass_out = read_passarg(args.pass_out)\n```\n\nThe program above then by default reads the input/output passphrases\nfrom the environment variables `${MY_PASS_IN}` and `${MY_PASS_OUT}`;\nif run with `--pass-in file:dec-pass.txt --pass-out stdin`,\nthen it reads the input/output passphrases\nfrom the file `dec-pass.txt` and the standard input respectively.\n\n# Passphrase Argument Syntax\n\npassarg supports the following OpenSSL-compatible arguments\n([openssl-passphrase-options(1)]):\n\n* **pass**:*password*\n\n  The actual password is *password*.\n  Since the password is visible to utilities (like 'ps' under Unix)\n  this form should only be used where security is not important.\n\n* **env**:*var*\n\n  Obtain the password from the environment variable *var*.\n  Since the environment of other processes is visible on certain platforms\n  (e.g. ps under certain Unix OSes)\n  this option should be used with caution.\n\n* **file**:*pathname*\n\n  Reads the password from the specified file *pathname*,\n  which can be a regular file, device, or named pipe.\n  Only the first line, up to the newline character, is read from the stream.\n\n  If the same *pathname* argument is supplied\n  to both **-passin** and **-passout** arguments,\n  the first line will be used for the input password,\n  and the next line will be used for the output password.\n\n* **fd**:*number*\n\n  Reads the password from the file descriptor *number*.\n  This can be useful for sending data via a pipe, for example.\n  The same line handling as described for **file:** applies\n  to passwords read from file descriptors.\n\n  **fd:** is not supported on Windows.\n\n* **stdin**\n\n  Reads the password from standard input.\n  The same line handling as described for **file:** applies\n  to passwords read from standard input.\n\npassarg also supports the following non-OpenSSL extensions:\n\n* **prompt**[:*text*]\n\n  Prompts the password using Python [getpass()].\n  If *text* is given, it is used as the prompt.\n  Otherwise, the getpass default (`Password: `) is used.\n\n* **op**:[//*Vault*/]*TitleOrID*[/*field*]\n\n  Fetches the given item using the [1Password CLI].\n  *Vault* is optional and defaults to `Private` or `Employee`;\n  *field* is also optional and defaults to `password`.\n\n# .env (\"dotenv\") File Support\n\npassarg can be combined with [python-dotenv] to add support for dotenv files.\nSimply call load_dotenv before entering the `passarg.reader()` context:\n\n```python\nfrom argparse import ArgumentParser\n\nimport dotenv\n\nimport passarg\n\nparser = ArgumentParser()\nparser.add_argument('--api-key', metavar='SPEC', default='env:MY_API_KEY')\nparser.add_argument('--env-file', metavar='PATH', default='.env')\nargs = parser.parse_args()\n\ndotenv.load_dotenv(args.env_file)\n\nwith passarg.reader() as read_passarg:\n    api_key = read_passarg(args.api_key)\n```\n\nThen it can be run in the directory with an `.env` file like:\n\n```\nMY_API_KEY=MySuperSecretKeyOmigod\n```\n\n# Passargs Sharing Same File-like Source\n\nAs explained in [Passphrase Argument Syntax](#passphrase-argument-syntax) above,\nmultiple passphrase arguments can share the same file-like source,\nwith each source reading one line from the source.\n\nThe order of calls to `read_passarg()` matters, and should be documented.\nFor example, the [Quickstart example](#quickstart) above\nreads `--pass-in` first then `--pass-out`,\nimplementing the same input-password-first ordering as with OpenSSL.\n\n[python-dotenv]: https://pypi.org/project/python-dotenv/\n[openssl-passphrase-options(1)]: https://docs.openssl.org/3.3/man1/openssl-passphrase-options/\n[getpass()]: https://docs.python.org/3/library/getpass.html#getpass.getpass\n[1Password CLI]: https://developer.1password.com/docs/cli/reference/management-commands/item#item-get\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "OpenSSL-style password argument handling.",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/astralblue/python-passarg"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "819142ae33d2458b5fd73dd53bee412fb6e0cd60e030cf078829f68a50ad4edc",
                "md5": "86879f74e23608db4b8fcdcefab32ccc",
                "sha256": "2d1c2d24fcb8db8a33bb841c54cfdfa0a4b0054fbf2a796762c87e3ef68f960e"
            },
            "downloads": -1,
            "filename": "passarg-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "86879f74e23608db4b8fcdcefab32ccc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.10",
            "size": 3964,
            "upload_time": "2024-08-03T07:14:44",
            "upload_time_iso_8601": "2024-08-03T07:14:44.570403Z",
            "url": "https://files.pythonhosted.org/packages/81/91/42ae33d2458b5fd73dd53bee412fb6e0cd60e030cf078829f68a50ad4edc/passarg-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3102c287bdd5328a6078ff92b6b841c0358e7c9b4794641b434eb423099a1088",
                "md5": "6740a97fdf1dc70fe859f11ec7b44719",
                "sha256": "5b11ab9591256138ab926b3a1275dae1ad95018b83861f47602c798e24d77f35"
            },
            "downloads": -1,
            "filename": "passarg-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6740a97fdf1dc70fe859f11ec7b44719",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.10",
            "size": 7330,
            "upload_time": "2024-08-03T07:14:45",
            "upload_time_iso_8601": "2024-08-03T07:14:45.663880Z",
            "url": "https://files.pythonhosted.org/packages/31/02/c287bdd5328a6078ff92b6b841c0358e7c9b4794641b434eb423099a1088/passarg-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-03 07:14:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "astralblue",
    "github_project": "python-passarg",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "passarg"
}
        
Elapsed time: 0.28650s