Skip to main content

1Password secrets source for pydantic-settings

Project description

pydantic-settings-op

A 1Password secrets source for pydantic-settings.

Installation

pip install pydantic-settings-op

Usage

from pydantic_settings import BaseSettings

from pydantic_settings_op import OPVaultSettingsSource


class Settings(BaseSettings):
    db_password: str
    api_key: str

    @classmethod
    def settings_customise_sources(cls, settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings):
        return (init_settings, env_settings, OPVaultSettingsSource(settings_cls, vault="MyVault"))

settings = Settings()

By convention, each field name is used as the 1Password item name within the configured vault, trying password then credential as the field name (configurable via default_fields).

Explicit field references with OPField

For fields that don't follow the convention, use OPField to specify an explicit secret reference:

from typing import Annotated

from pydantic_settings_op import OPField

class Settings(BaseSettings):
    # Relative path — vault from OPVaultSettingsSource is prepended
    db_password: Annotated[str, OPField("database/password")]

    # Full URI — uses the specified vault, ignoring the source vault
    api_key: Annotated[str, OPField("op://other-vault/api/key")]

Authentication

Authentication is resolved in order:

  1. Explicit auth parameter (a service account token string or DesktopAuth instance)
  2. OP_SERVICE_ACCOUNT_TOKEN environment variable
  3. OP_ACCOUNT_NAME environment variable (uses DesktopAuth)

You can also pass a pre-configured client directly instead of using auth.

Aliases

The source respects pydantic's alias, validation_alias, and AliasChoices when emitting keys, so resolved secrets integrate with your existing alias configuration.

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

pydantic_settings_op-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

pydantic_settings_op-0.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_settings_op-0.1.0.tar.gz.

File metadata

  • Download URL: pydantic_settings_op-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pydantic_settings_op-0.1.0.tar.gz
Algorithm Hash digest
SHA256 10e4a2bab9400566e84137011df4b25420d0d74aebe70354befd9f58b7164624
MD5 6758e1b378a8ea18eb0eaeedd2a9c2c4
BLAKE2b-256 218ab844f44fa4e18f0982f21673eb062aa34ceae49b67f1faaa087c7c6e3c38

See more details on using hashes here.

File details

Details for the file pydantic_settings_op-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic_settings_op-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pydantic_settings_op-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f84b80caaa127f772c88ddd8b854ce47ba451cf684419b73bddf45c8f01c0d8
MD5 7bc61e29e0f50e2182a63bf665b820c3
BLAKE2b-256 d66f45967f8bb6c21684a35f70054ece63ddffd2789ae07a511ae6e0de2ac961

See more details on using hashes here.

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