Skip to main content

Object Relational Mapping for 1Password items, manage 1Password vaults with code.

Project description

1Password ORM

A robust Python ORM for managing 1Password secrets with elegance. This library provides a secure, type-safe interface for interacting with 1Password items using familiar ORM patterns.

🌟 Key Features

  • 🔐 Type-safe field definitions with built-in validation
  • 🔄 Automated password generation and management
  • 🎯 Clean, Pythonic model-based structure
  • 🔑 Comprehensive support for all 1Password item types
  • 🚀 Easy CRUD operations with version tracking
  • 🔒 Secure integration with 1Password Connect
  • 📦 Kubernetes secrets generation

📦 Installation

pip install op-orm

🔧 Quick Start

  1. Set up environment variables:
export OP_CONNECT_TOKEN="your-1password-connect-token"
export OP_INTEGRATION_NAME="your-app-name"
  1. Define your models:
from op_orm.types import OpModelDatabase, StringField, PasswordField, UrlField

class PostgresDatabase(OpModelDatabase):
    title = "production-postgres"
    sections = ["connection", "auth"]
    
    host = StringField(section_id="connection", value="db.example.com")
    port = StringField(section_id="connection", value="5432")
    database = StringField(section_id="connection", value="myapp")
    username = StringField(section_id="auth", value="admin")
    password = PasswordField(section_id="auth")
  1. Use your models:
# Create and save credentials
db = PostgresDatabase()
db.password.generate_password()  # Generates secure random password
db.create()

# Update credentials
db.update_existing_fields({
    "username": "new_admin",
    "host": "new-db.example.com"
})

# Retrieve credentials
db.resolve_all()  # Fetches latest values from 1Password
print(f"Connection string: postgresql://{db.username.value}@{db.host.value}")

🏗️ Model Types

The library provides specialized models for common credential types:

  • OpModelServer - Server credentials
  • OpModelDatabase - Database connections
  • OpModelAPIKey - API credentials
  • OpModelLogin - Login credentials
  • OpModelSSHKey - SSH keys
  • OpModelSecureNote - Secure notes
  • And more...

🔐 Field Types

Available field types for model attributes:

  • StringField - Text values (optionally concealed)
  • PasswordField - Auto-generating password fields
  • UrlField - URL fields with validation

🚀 Advanced Usage

Kubernetes Secret Generation

Generate Kubernetes secrets from your models:

from op_orm.deployment_generator import generate_deployment_files

# Generate YAML for k8s secrets
deployment = generate_deployment_files([PostgresDatabase])
with open("k8s-secrets.yaml", "w") as f:
    f.write(deployment)

Custom Field Validation

Add custom validation to your fields:

class APICredentials(OpModelAPIKey):
    api_key = StringField(section_id="api", concealed=True)
    environment = StringField(section_id="api")
    
    def validate(self):
        if self.environment.value not in ["prod", "staging", "dev"]:
            raise ValueError("Invalid environment")

Generate Kubernetes Secrets from OpModel

The generate_deployments command-line tool streamlines the integration between your Python OpModel classes and the 1Password Kubernetes Operator (connect). It automates the process of creating Kubernetes secret definitions by scanning your Python files for OpModel subclasses and converting them into the appropriate YAML format required by the 1Password k8s operator.

Usage

  • Use -p flag to preview the generated YAML in terminal
  • Use -o flag followed by a filename to save the deployments
  • Simply point to your Python file containing OpModel definitions

This tool helps bridge the gap between your application's secrets management and the 1Password Kubernetes Operator, ensuring smooth deployment of your secrets in a Kubernetes environment.

usage: generate_deployments [-h] [-p] [-o OUTPUT] file_path

Collect OpModel subclasses from a Python file.

positional arguments:
  file_path             Path to the Python file.

options:
  -h, --help            show this help message and exit
  -p, --print           print to stdout
  -o OUTPUT, --output OUTPUT
                        File to save the k8s secret deployments.

Example usage:

generate_deployments examples/example_models.py -p -o secrets.yaml 

This will output the 1password k8s items in a single deployment file

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the GPL3 License - see the LICENSE file for details.

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

op_orm-0.2.1.tar.gz (49.5 kB view details)

Uploaded Source

Built Distribution

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

op_orm-0.2.1-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file op_orm-0.2.1.tar.gz.

File metadata

  • Download URL: op_orm-0.2.1.tar.gz
  • Upload date:
  • Size: 49.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for op_orm-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e5c23015e1579ded5ea76f20dc4cd74ecbde19b1fc59da111ecbbe3b94b46b0b
MD5 d9f4a6a315ad66d1306fd594b280b352
BLAKE2b-256 589609766c1d7598618fd9f008b375fb50fc617bcb7547e6933a271dae72a166

See more details on using hashes here.

Provenance

The following attestation bundles were made for op_orm-0.2.1.tar.gz:

Publisher: upload-to-pypi.yml on Ilke-dev/op-orm

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

File details

Details for the file op_orm-0.2.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for op_orm-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d073871abac938efe771d6b45a4bcd2db432b46f31cce5f125e7212460a727dd
MD5 fa0782527918acd5f4f28f1bf8d21864
BLAKE2b-256 c8a14d16600eed6707ad5ed5329975a5eeca72c1c2eddaa44a86ebb0191b7ae8

See more details on using hashes here.

Provenance

The following attestation bundles were made for op_orm-0.2.1-py3-none-any.whl:

Publisher: upload-to-pypi.yml on Ilke-dev/op-orm

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