Architecture¶
prov is one package, src/prov/, in layers that depend in one direction with one
deliberate exception. prov.model imports prov.serializers so that serialize() and
deserialize() can dispatch through the registry, and the format modules import
prov.model back. The registry breaks the cycle by importing the format modules lazily,
on first use. Reading the layers in order gives the shape of the library.
Layers¶
Module |
Responsibility |
Depends on |
|---|---|---|
|
|
standard library |
|
The PROV vocabulary as |
|
|
The in-memory data model: records, bundles, documents and namespace management |
|
|
One module per format behind a registry; |
|
|
|
|
|
|
|
|
|
|
|
The |
|
prov.model is a package (records.py, bundle.py, namespaces.py, _values.py for assertion-time value checks) whose __init__.py
re-exports every public name at its historic prov.model location. User code imports from
prov.model and never from the submodules. Both prov.model.__init__ and
prov.model.bundle import prov.serializers at module load time.
The object model¶
A ProvRecord is a PROV type, an optional identifier and an ordered multi-valued attribute
map. ProvElement (entity, activity, agent) and ProvRelation (generation, usage,
derivation and the rest) split the PROV-DM world between them. Each concrete class declares
its formal attributes in order. Everything else on the record is an “other” attribute.
A ProvBundle owns records and a namespace manager that registers
the namespaces the bundle binds and those its records use that no enclosing scope declares,
and offers a factory method per record type (entity(), wasGeneratedBy(), …). A
ProvDocument is a bundle that can also contain named bundles, and
is the unit that serializes. Records are created through the bundle so that identifiers
resolve against its namespaces.
Two transformations leave the original untouched. unified()
merges records that share an identifier under the PROV-CONSTRAINTS rules and returns a new
document. flattened() lifts bundle contents to the top
level and returns a new document, or the document itself when it has no bundles. See
Unification and flattening.
Serializers and format detection¶
Each serializer subclasses Serializer and implements
serialize() and deserialize(). prov.serializers.Registry holds them under their
format names, and prov.serializers.get() resolves a name to a class.
Detect the format with prov.read() gives the registry order and shows how prov.read() walks it.
Registry.load_serializers() fills
the registry on first use and leaves out a format whose optional parser is not installed.
Extras¶
The core package has no runtime dependencies. Each optional capability sits behind an
extra, and Installation lists which extra installs which package. prov.graph,
prov.dot and prov.pygments raise ModuleNotFoundError naming the extra when imported
without it. prov.pygments imports nothing from prov, and Developer guide gives
the reason.