Python library for generating OPA (Open Prompt Archive) files
Project description
opa-archive
A Python library for creating and signing OPA (Open Prompt Archive) files.
OPA is a ZIP-based archive format for packaging AI prompts together with data assets, session history, and metadata -- similar to how JAR files package Java applications.
Installation
pip install opa-archive
Quick Start
from opa import OpaArchive, Manifest, Prompt, ExecutionMode
manifest = Manifest(
title="My Prompt",
description="A packaged AI prompt with data",
execution_mode=ExecutionMode.BATCH,
)
prompt = Prompt("Summarise the attached data file.")
archive = OpaArchive(manifest=manifest, prompt=prompt)
archive.add_data_file("data/report.csv", "local/report.csv")
archive.write("my_prompt.opa")
Features
- Manifest -- JAR-style
MANIFEST.MFwith title, description, execution mode, and custom fields. - Prompt -- Markdown prompt files with
{{variable}}template support. - Data assets -- Bundle arbitrary files and directories with a typed
INDEX.jsoncatalog. - Session history -- Include multi-turn conversation context (text, images, tool use).
- Signing -- JAR-compatible PKCS#7 digital signatures using the
cryptographylibrary or theopensslCLI.
Signing an Archive
from opa import OpaArchive, Manifest, Prompt, Signer
from opa import generate_signing_key, generate_self_signed_cert
# Build the archive
archive = OpaArchive(
manifest=Manifest(title="Signed Example"),
prompt=Prompt("Hello, world!"),
)
archive.write("example.opa")
# Generate a key pair and sign
private_key = generate_signing_key(key_type="rsa", key_size=2048)
certificate = generate_self_signed_cert(private_key, common_name="My Signer")
signer = Signer(private_key=private_key, certificate=certificate)
signer.sign("example.opa")
You can also load existing PEM keys:
from opa import load_private_key, load_certificate, Signer
key = load_private_key("key.pem")
cert = load_certificate("cert.pem")
signer = Signer(private_key=key, certificate=cert)
signer.sign("example.opa")
Template Variables
Prompts support {{variable}} placeholders:
prompt = Prompt("Translate the following to {{language}}:\n\n{{text}}")
print(prompt.variables()) # {'language', 'text'}
print(prompt.render({"language": "French", "text": "Hello"}))
Data Assets
Bundle files with a typed index:
from opa import DataIndex
index = DataIndex()
index.add("data/feed.xml", description="RSS feed", content_type="application/rss+xml")
index.add("data/config.json", description="Config file", content_type="application/json")
archive.set_data_index(index)
archive.add_data_file("data/feed.xml", "local/feed.xml")
archive.add_data_dir("local/data_folder/", archive_prefix="data/")
Session History
Include conversation context:
from opa import SessionHistory
session = SessionHistory()
session.add_user("What is the capital of France?")
session.add_assistant("The capital of France is Paris.")
archive.set_session(session)
Dependencies
The core library has no required dependencies. Signing works out of the box if openssl is on your PATH. Install the optional cryptography package for native Python signing:
pip install opa-archive[crypto]
License
MIT
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 opa_archive-0.1.0.tar.gz.
File metadata
- Download URL: opa_archive-0.1.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07a70fb1df6a6ba279fddd3563c72c5ab97aed1fb5a1e32cd1ec4988d48fb3cc
|
|
| MD5 |
25277779e67469a1b82c735b0016ac4f
|
|
| BLAKE2b-256 |
f09d7b32dccfda03ff6c77d97371966372687fbe6777e0a6c560cc6e4aabd929
|
Provenance
The following attestation bundles were made for opa_archive-0.1.0.tar.gz:
Publisher:
publish.yml on shannah/opa-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opa_archive-0.1.0.tar.gz -
Subject digest:
07a70fb1df6a6ba279fddd3563c72c5ab97aed1fb5a1e32cd1ec4988d48fb3cc - Sigstore transparency entry: 1059803042
- Sigstore integration time:
-
Permalink:
shannah/opa-python@06dcabb62bf31b17cbf92ddfffec588f166ce25c -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/shannah
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@06dcabb62bf31b17cbf92ddfffec588f166ce25c -
Trigger Event:
release
-
Statement type:
File details
Details for the file opa_archive-0.1.0-py3-none-any.whl.
File metadata
- Download URL: opa_archive-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.1 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 |
371a288d1ef7e6581a4d0b73e08a2947b7dee8ef55e45b34152ba18b898ac030
|
|
| MD5 |
a39c2678ff213bf6c78b9145d82a2541
|
|
| BLAKE2b-256 |
aa11073c623a85dc816ae0192167eced8ccfe3f613a6474fa73fbefa8b19f3a9
|
Provenance
The following attestation bundles were made for opa_archive-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on shannah/opa-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opa_archive-0.1.0-py3-none-any.whl -
Subject digest:
371a288d1ef7e6581a4d0b73e08a2947b7dee8ef55e45b34152ba18b898ac030 - Sigstore transparency entry: 1059803049
- Sigstore integration time:
-
Permalink:
shannah/opa-python@06dcabb62bf31b17cbf92ddfffec588f166ce25c -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/shannah
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@06dcabb62bf31b17cbf92ddfffec588f166ce25c -
Trigger Event:
release
-
Statement type: