Skip to main content

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.MF with 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.json catalog.
  • Session history -- Include multi-turn conversation context (text, images, tool use).
  • Signing -- JAR-compatible PKCS#7 digital signatures using the cryptography library or the openssl CLI.

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


Download files

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

Source Distribution

opa_archive-0.1.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

opa_archive-0.1.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

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

Hashes for opa_archive-0.1.0.tar.gz
Algorithm Hash digest
SHA256 07a70fb1df6a6ba279fddd3563c72c5ab97aed1fb5a1e32cd1ec4988d48fb3cc
MD5 25277779e67469a1b82c735b0016ac4f
BLAKE2b-256 f09d7b32dccfda03ff6c77d97371966372687fbe6777e0a6c560cc6e4aabd929

See more details on using hashes here.

Provenance

The following attestation bundles were made for opa_archive-0.1.0.tar.gz:

Publisher: publish.yml on shannah/opa-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 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

Hashes for opa_archive-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 371a288d1ef7e6581a4d0b73e08a2947b7dee8ef55e45b34152ba18b898ac030
MD5 a39c2678ff213bf6c78b9145d82a2541
BLAKE2b-256 aa11073c623a85dc816ae0192167eced8ccfe3f613a6474fa73fbefa8b19f3a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for opa_archive-0.1.0-py3-none-any.whl:

Publisher: publish.yml on shannah/opa-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