Skip to main content

Python wrapper around the 1Password CLI with Pydantic Settings integration

Project description

1Password CLI Python Wrapper

PyPI version Python Support License: MIT CI/CD Coverage

Python wrapper for 1Password CLI with Pydantic Settings integration. Automatically injects secrets from op:// references while preserving types.

Features

  • Automatic secret injection with op:// reference detection
  • Pydantic Settings integration with pre-validation injection
  • Type preservation (int, float, bool, None, lists)
  • Full type hints with py.typed marker
  • Performance optimized (skips CLI calls when no secrets detected)
  • Timeout protection and clear error messages

Installation

pip install 1password-cli

Prerequisites: 1Password CLI installed and authenticated (op signin)

Usage

String injection:

from scottzach1.onepassword_cli import inject_string_1password

password = inject_string_1password("op://vault/database/password")

Dictionary injection:

from scottzach1.onepassword_cli import inject_dictionary_1password

config = {
    "database_url": "op://vault/database/url",
    "api_key": "op://vault/api/key",
    "port": 5432,  # Non-secret values preserved
}
injected = inject_dictionary_1password(config)

Pydantic Settings:

from scottzach1.onepassword_cli import OnePasswordSettings

class AppSettings(OnePasswordSettings):
    database_url: str = "op://vault/database/url"
    api_key: str = "op://vault/api/key"
    port: int = 8080

settings = AppSettings()  # Secrets injected automatically

API

  • inject_string_1password(value, check_cli=True) - Inject secrets into a string
  • inject_dictionary_1password(data, check_cli=True, in_place=False) - Inject secrets into a dictionary
  • OnePasswordSettings - Pydantic Settings base class with automatic injection

See docstrings for parameters and exceptions.

Development

# Setup
uv sync --dev && uv run pre-commit install

# Test
uv run pytest tests/ -v -m "not integration"
uv run coverage run -m pytest tests/ -m "not integration"

# Lint/Format
uv run ruff check src/ tests/ --fix
uv run ruff format src/ tests/

License

MIT License - see LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

1password_cli-0.0.1.tar.gz (68.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

1password_cli-0.0.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file 1password_cli-0.0.1.tar.gz.

File metadata

  • Download URL: 1password_cli-0.0.1.tar.gz
  • Upload date:
  • Size: 68.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for 1password_cli-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a277c66acc10e46f92f71df2af751eceee6e52354a6dee9d108b0ef339f52bb9
MD5 5d2d208103c50feacd4fc20ea33f41f5
BLAKE2b-256 197afc4c69b583d479fee5645080e4f1bd70c6df4b016447217f473ef9a54368

See more details on using hashes here.

Provenance

The following attestation bundles were made for 1password_cli-0.0.1.tar.gz:

Publisher: pipeline.yml on scottzach1/1Password-CLI-Python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file 1password_cli-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: 1password_cli-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for 1password_cli-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 22cc63c8973a8e70900e9e4c38c1e5495aaefcca8d6135e80af596f02abc89e6
MD5 b61fe3e4de20b6b35dd495f7cc984f6b
BLAKE2b-256 09ff6fd72ca55d5bff66ba87c5867ce96533d28e3c6b9d9ea8811a35b0d0e205

See more details on using hashes here.

Provenance

The following attestation bundles were made for 1password_cli-0.0.1-py3-none-any.whl:

Publisher: pipeline.yml on scottzach1/1Password-CLI-Python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page