Skip to main content

passarg: OpenSSL password/-phrase argument

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

Quickstart

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:

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 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 above reads --pass-in first then --pass-out, implementing the same input-password-first ordering as with OpenSSL.

Metadata

Release files for passarg 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for passarg 0.1.0
File Size Uploaded Provenance
passarg-0.1.0.tar.gz 7.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for passarg 0.1.0
File Interpreter ABI Platform
passarg-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / passarg-0.1.0.tar.gz

Download URL passarg-0.1.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5b11ab9591256138ab926b3a1275dae1ad95018b83861f47602c798e24d77f35
BLAKE2b-256 checksum
How to use checksums
3102c287bdd5328a6078ff92b6b841c0358e7c9b4794641b434eb423099a1088
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / passarg-0.1.0-py3-none-any.whl

Download URL passarg-0.1.0-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d1c2d24fcb8db8a33bb841c54cfdfa0a4b0054fbf2a796762c87e3ef68f960e
BLAKE2b-256 checksum
How to use checksums
819142ae33d2458b5fd73dd53bee412fb6e0cd60e030cf078829f68a50ad4edc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Security for passarg 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page