Python quickstart¶
The Python package uses the installed public C ABI through the standard
library’s ctypes module. It requires Python 3.11 or newer and does not build
or import Rust code.
Install the platform wheel for your system, and the binding loads the native library inside it (see Install a release). With the platform-neutral wheel, point the binding at an exact native library instead:
export POSTPROJECT_LIBRARY=/opt/postproject/lib/libpostproject.so
python /opt/postproject/share/doc/postproject/examples/python/quickstart.py \
production.pproj \
/opt/postproject/share/doc/postproject/examples/fixtures/sample-media.dat
Applications may instead pass library_path= to Production.create or
Production.open; the quickstart does so when given --library PATH. An
explicit path wins, then POSTPROJECT_LIBRARY, then a platform wheel’s own
library. The binding does not search the working directory or modify the
platform loader path, and it loads each library once per process. The
installed quickstart above runs in package CI on Linux, macOS, and Windows.
An Edit context requires explicit commit(). Every uncommitted exit
rolls back, including normal exit. close() is idempotent for production and
edit handles, and a
finalizer is a fallback for handles that were not closed explicitly.
Use production.edit() for additive writes and production.edit(base) for
work decided from a detached view.decision_base. Use view.edit() when
staging needs the retained read knowledge. Both constructors accept origin=
and message=. The Coherent reads and scoped edits recipe explains the lifetime rules.
Identity annotations such as AssetId are NewType hints over ordinary
uuid.UUID values. Use parse_id(text, AssetId) to parse text, standard UUID
operations at serialization boundaries, and optional type checking to catch
wrong-kind arguments. Use explicit AssetRef(asset_id) or
RepresentationRef(representation_id) variants for metadata, dependency,
external-identifier, and host-binding targets. A runtime UUID does not retain
its nominal type; the store checks existence and production membership.
Integer arguments must fit their native ranges; conversion never wraps them.
Booleans and other non-integers raise TypeError; overflowing integers raise
InvalidArgumentError. Native operations also check domain limits.
Closed owners and finished edits raise InvalidArgumentError. Required unknown
native tags or an incompatible ABI raise UnsupportedError; inconsistent native
payloads raise InternalError. These exceptions carry the corresponding native
code. Repeated close() calls are harmless.
Production operations may run concurrently from multiple Python threads; calls
on one native handle serialize internally. Do not call close() concurrently
with an operation, and do not share an edit between concurrent callers.
Open the production again when reads should use a separate native handle during
a commit.
The quickstart program shows each of these rules:
"""Create a production and import one opaque media fixture."""
from __future__ import annotations
import argparse
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from postproject import OriginIdentity, Production
class Cancelled(Exception):
"""Raised to abandon a change before it is committed."""
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("production", type=Path)
parser.add_argument("media", type=Path)
parser.add_argument(
"--library",
type=Path,
help="native library to load instead of POSTPROJECT_LIBRARY",
)
args = parser.parse_args()
# library_path=None falls back to the POSTPROJECT_LIBRARY variable. The
# binding never searches the working directory or the loader path.
with Production.create(
args.production, "Python quickstart", library_path=args.library
) as production:
# Commit explicitly; an uncommitted context always rolls back.
with production.edit(
origin=OriginIdentity("org.postproject:python-quickstart"),
message="Import quickstart media",
) as transaction:
asset_id = transaction.import_media(
args.media, display_name="Quickstart media"
).asset_id
transaction.commit()
# An exception escaping the context rolls the transaction back.
try:
with production.edit() as transaction:
transaction.add_media_root("proxies")
raise Cancelled
except Cancelled:
pass
assert production.media_roots == ()
# Threads may share one production; calls on it serialize internally.
with ThreadPoolExecutor(max_workers=4) as pool:
counts = list(
pool.map(lambda _: len(production.representations[asset_id]), range(4))
)
print(f"representations: {counts[0]}")
# A separately opened handle does not wait for calls on the first one,
# such as a long commit.
reader = Production.open(args.production, library_path=args.library)
assert reader.asset_exists(asset_id)
reader.close()
production.close() # The context closed it already; this is harmless.
if __name__ == "__main__":
main()
The current high-level surface covers production lifecycle, staged edits,
original-media import, revision context, scoped asset/revision scans,
typed membership queries and bounded semantic events.
External identifiers can be added,
removed, enumerated, and found by exact scheme and value. Metadata reads and
writes preserve every typed value kind; scalar, repeated, structured, and
reference values use edit.add_metadata(). Common inputs use a
(vocabulary, property) tuple with str, bool, signed int, bytes or
Fraction values. Ambiguous kinds stay explicit; see Metadata vocabularies. Provenance activities can be
created and queried through immutable value objects and keyed graph views.
production.resolve(asset_id, {"rushes": "/mnt/show/rushes"}) returns typed
representation availability, resource candidates, evidence, diagnostics, and
missing-frame details while supplying machine-local paths for named production
roots. production.resolutions[asset_id] is the shorthand when no mappings are
needed.
production.representations[asset_id] returns the
stored structure, ordered membership, compact sequence descriptor, resources,
locators with their sequence namings, and distinct resource and representation fingerprints as immutable
values. production.media_roots lists immutable logical-root summaries in
resolver order. Root creation takes a portable name rather than a directory;
local paths are supplied to resolve(). Root creation, enablement, removal,
locator retirement, and explicit
candidate confirmation are transactional through add_media_root(),
set_media_root_enabled(), remove_media_root(), retire_locator(),
and confirm_locator(), which also records the logical root a candidate was
found under and, for an image sequence, the SequenceNaming of its files. A compound source — ImageSequenceSource, OrderedPartsSource, or
PackageSource — describes a
representation’s content structure: import_media() creates an asset whose
original has that structure, and add_representation() adds a representation
of a chosen kind to an existing asset. Both also accept a plain path as a
single file. The generated low-level declaration table covers every
function and struct in the current ABI.
Production-sized reads are bounded queries that take a
keyword limit and an optional cursor and return a QueryPage with items,
next_cursor, and traversal_truncated: assets_page(),
representations_page(), resources_page(), locators_page(),
unresolved_media(), representations_under_media_root(), query_metadata(),
activities_producing_page(), activities_consuming_page(),
outputs_by_activity_kind(), outputs_by_tool(),
provenance_ancestors_page(), provenance_descendants_page(),
dependencies(), dependents(), stale_artifacts(), jobs(), and
objects_changed_since().
For a coherent asset scan, open a read session and iterate
view.assets(page_size=100) or view.revisions(after=0, page_size=100).
Both scan the pinned view and load one bounded page at a time;
page size bounds memory, not total work. Close the session before long host
work. Advancing an unfinished iterator after session close raises
InvalidArgumentError; copied assets remain usable. Use
production.asset_exists(asset_id) for a live membership check. The former
production.assets collection is removed.
Plug-ins of a host application¶
Applications that embed Python, such as Blender, Nuke, Houdini, or Maya, often share one Python environment among all their plug-ins. Ship PostProject with a plug-in this way:
Bundle the platform wheel and pass no library path. The wheel’s binding and library always match.
Expect to share it. Blender, for example, installs the wheels of all extensions into one
site-packagesand keeps only the newest wheel of each name. Another plug-in may bring a newer PostProject than yours, and before 1.0 its Python API may differ from the one you built against.Never set
POSTPROJECT_LIBRARYfrom a plug-in. The variable is process-wide and would override every other plug-in’s library.
The Blender pilot is an extension packaged this way.
Image-sequence sources take an exact fractions.Fraction rate, for example
rate=Fraction(24000, 1001). Read descriptors expose the same standard type
through sequence.rate. Nonpositive or out-of-range rates fail before import.