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
- Set up environment variables:
export OP_CONNECT_TOKEN="your-1password-connect-token"
export OP_INTEGRATION_NAME="your-app-name"
- 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")
- 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 credentialsOpModelDatabase- Database connectionsOpModelAPIKey- API credentialsOpModelLogin- Login credentialsOpModelSSHKey- SSH keysOpModelSecureNote- Secure notes- And more...
🔐 Field Types
Available field types for model attributes:
StringField- Text values (optionally concealed)PasswordField- Auto-generating password fieldsUrlField- 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
-pflag to preview the generated YAML in terminal - Use
-oflag 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5c23015e1579ded5ea76f20dc4cd74ecbde19b1fc59da111ecbbe3b94b46b0b
|
|
| MD5 |
d9f4a6a315ad66d1306fd594b280b352
|
|
| BLAKE2b-256 |
589609766c1d7598618fd9f008b375fb50fc617bcb7547e6933a271dae72a166
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
op_orm-0.2.1.tar.gz -
Subject digest:
e5c23015e1579ded5ea76f20dc4cd74ecbde19b1fc59da111ecbbe3b94b46b0b - Sigstore transparency entry: 730494612
- Sigstore integration time:
-
Permalink:
Ilke-dev/op-orm@73e66924fb80bc555a6a35791d355e2e579e7879 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Ilke-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
upload-to-pypi.yml@73e66924fb80bc555a6a35791d355e2e579e7879 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d073871abac938efe771d6b45a4bcd2db432b46f31cce5f125e7212460a727dd
|
|
| MD5 |
fa0782527918acd5f4f28f1bf8d21864
|
|
| BLAKE2b-256 |
c8a14d16600eed6707ad5ed5329975a5eeca72c1c2eddaa44a86ebb0191b7ae8
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
op_orm-0.2.1-py3-none-any.whl -
Subject digest:
d073871abac938efe771d6b45a4bcd2db432b46f31cce5f125e7212460a727dd - Sigstore transparency entry: 730494614
- Sigstore integration time:
-
Permalink:
Ilke-dev/op-orm@73e66924fb80bc555a6a35791d355e2e579e7879 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Ilke-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
upload-to-pypi.yml@73e66924fb80bc555a6a35791d355e2e579e7879 -
Trigger Event:
release
-
Statement type: