prov.model

prov.model is the in-memory object model for PROV-DM documents. A ProvDocument contains ProvBundle objects, which hold records. Records are elements (entities, activities, agents) and the relations between them. The namespace machinery that builds and resolves their identifiers lives here too. Attribute values and equality covers how records store attribute values and when two of them are equal. The Getting started walks through building a document with this API, and the PROV-DM Primer covers the concepts behind the classes.

Documents and bundles

class prov.model.ProvDocument(records: Iterable[ProvRecord] | None = None, namespaces: NSCollection | None = None)[source]

Bases: ProvBundle

The top-level container of a PROV document.

A document holds records and named bundles. serialize() writes one, and prov.read() returns one.

plot(filename: str | bytes | PathLike[str] | None = None, show_nary: bool = True, use_labels: bool = False, show_element_attributes: bool = True, show_relation_attributes: bool = True) → None

Plot the document as a graph, saving to a file or displaying it.

The graph is the one prov.dot.prov_to_dot() draws. A bundle that is not a document warns DeprecationWarning, as prov.dot.prov_to_dot() does, and 4.0 draws documents only.

Parameters:
  • filename – The path to save the plot to, written through Graphviz; the image format is derived from its extension. If not given, the plot is shown through matplotlib, in an interactive window or inline in a notebook (default: None).

  • show_nary – Whether to show all elements in n-ary relations (default: True).

  • use_labels – Whether to label elements by their prov:label property instead of their identifier (default: False).

  • show_element_attributes – Whether to show element attributes (default: True).

  • show_relation_attributes – Whether to show relation attributes (default: True).

Raises:
  • ValueError – If the format implied by filename cannot be saved.

  • ImportError – If no filename is given but matplotlib is not installed.

is_document() → bool[source]

Return True if this is a document, False otherwise.

is_bundle() → bool[source]

Return True if this is a (named) bundle, False otherwise.

has_bundles() → bool[source]

Return True if the document contains bundles, False otherwise.

property bundles: ValuesView[ProvBundle]

The bundles contained in this document.

flattened() → ProvDocument[source]

Return a new document with all bundle records lifted to the top level.

Every record from every bundle is moved up alongside the document’s own records and the bundle structure is discarded; this is purely structural (nothing is merged or deduplicated). If the document has no bundles, it is returned unchanged. The original document is left untouched.

Returns:

The (new) flattened ProvDocument, or this document itself if it has no bundles.

unified() → ProvDocument[source]

Return a new document with records sharing an identifier merged.

Records that share an identifier in one scope, the document’s top level or one bundle, merge into one record, and the original document is left untouched. After the merge, a record equal to an earlier one is dropped. Records that share an identifier but cannot merge raise ProvUnificationError. Unification and flattening gives the rules, the exceptions and the limits.

Returns:

The new, unified ProvDocument.

Raises:

ProvUnificationError – If two records sharing an identifier within the same scope hold different concrete values for the same formal attribute, or one leaves out a value in a position that cannot take one, such as an association’s plan, where another holds a concrete one, or the records have incompatible types, such as an entity and an activity.

update(other: ProvBundle) → None[source]

Append all records of another document or bundle into this document.

Any bundles of other are also merged in: a bundle whose identifier already exists in this document is updated in place, otherwise a new bundle is created.

Parameters:

other – The ProvDocument or ProvBundle whose records are appended.

Raises:

ProvException – If other is not a ProvBundle (or subclass).

add_bundle(bundle: ProvBundle, identifier: QualifiedNameCandidate | None = None) → None[source]

Add a bundle to this document.

If a document (with no nested bundles) is passed, its records are copied into a fresh bundle. The bundle’s identifier resolves against the bundle’s own namespaces first and then this document’s.

Parameters:
  • bundle – The ProvBundle to add.

  • identifier – Optional identifier to use for the bundle; if not given, the bundle’s own identifier is used (default: None).

Raises:
  • ProvException – If bundle is not a ProvBundle, is a document with nested bundles, has no usable identifier, or an identifier collides with an existing bundle, or bundle already belongs to another document.

  • ProvExceptionInvalidQualifiedName – If no namespace resolves identifier.

bundle(identifier: QualifiedNameCandidate) → ProvBundle[source]

Create a new, empty named bundle in this document.

Parameters:

identifier – The identifier to use for the bundle.

Returns:

The newly created ProvBundle.

Raises:
serialize(destination: None = None, format: str = 'json', **args: Any) → str[source]
serialize(destination: StreamOrPath, format: str = 'json', **args: Any) → None
serialize(destination: StreamOrPath | None, format: str = 'json', **args: Any) → str | None

Serialize this document to a destination or return it as a string.

The available serialization formats are "json", "rdf", "xml", "provn" and "jsonld" (see prov.serializers.get()).

Parameters:
  • destination – A writable stream (any object with a write method) or a local file path to write to. If None, the serialization is returned as a string (default: None). A non-local (network) location is not written and yields None.

  • format – The serialization format (default: "json", i.e. PROV-JSON).

  • **args – Extra keyword arguments passed to the underlying serializer.

Returns:

The serialization as a string if no destination was given, otherwise None.

static deserialize(source: StreamOrPath | None = None, content: str | bytes | None = None, format: str = 'json', **args: Any) → ProvDocument[source]

Deserialize a document from a source stream/file or a string.

Exactly one of source or content should be given; content takes precedence if both are.

Parameters:
  • source – A readable stream (any object with a read method) or a file path to read from (default: None).

  • content – The document as a str or bytes to read from (default: None).

  • format – The serialization format (default: "json", i.e. PROV-JSON).

  • **args – Extra keyword arguments passed to the underlying deserializer.

Returns:

The deserialized ProvDocument.

Raises:

TypeError – If neither source nor content is provided.

class prov.model.ProvBundle(records: Iterable[ProvRecord] | None = None, identifier: QualifiedName | None = None, namespaces: NSCollection | None = None, document: ProvDocument | None = None, *, _parent: ProvDocument | None = None)[source]

Bases: object

A named or anonymous set of PROV records with its own namespaces.

A bundle holds records, has an optional identifier and registers only the namespaces it binds itself, together with any namespace that its records use and no enclosing scope declares. A name in a namespace that the document declares resolves through the document. ProvDocument is the subclass that also holds bundles.

property namespaces: set[Namespace]

The set of the bundle’s registered namespaces.

property default_ns_uri: str | None

The bundle’s default namespace URI, or None if none is set.

property document: ProvDocument | None

The parent document of this bundle, or None if it has none.

Deprecated since version 3.3.0: Keep a reference to the ProvDocument that holds the bundle; 4.0 removes this property.

property identifier: QualifiedName | None

The bundle’s identifier, or None if it has none.

property records: list[ProvRecord]

A copy of the list of all records in this bundle.

set_default_namespace(uri: str) → None[source]

Set the bundle’s default namespace to one with the given URI.

Parameters:

uri – The URI of the default namespace.

Raises:
  • ProvValueError – If uri is blank or starts with @.

  • ProvException – If the bundle holds a name in the current default namespace, which the new one would make another name.

get_default_namespace() → Namespace | None[source]

Return the default namespace, or None if none is set.

add_namespace(namespace_or_prefix: Namespace | str, uri: str | None = None) → Namespace[source]

Add a namespace to the bundle, unless an equivalent one exists.

Parameters:
  • namespace_or_prefix – A Namespace to add, or a prefix string (in which case uri is required).

  • uri – The namespace URI; required when namespace_or_prefix is a prefix string (default: None).

Returns:

The registered namespace (which may be an existing or renamed one).

Raises:
  • ProvException – If a prefix string is given without a uri, or the prefix is not bound here but an enclosing scope binds it and the bundle holds a name in that binding, which the new namespace would make another name.

  • ProvValueError – If a prefix string is given that is empty or is not a PN_PREFIX, or whose uri is blank or starts with @.

get_registered_namespaces() → Iterable[Namespace][source]

Return all namespaces registered on the bundle.

Returns:

An iterable of Namespace.

valid_qualified_name(identifier: QualifiedNameCandidate) → QualifiedName | None[source]

Resolve an identifier to a qualified name using this bundle.

Parameters:

identifier – The candidate to resolve.

Returns:

The resolved QualifiedName, or None if it could not be resolved.

Raises:

ProvExceptionInvalidQualifiedName – If the local part is one PROV-N cannot write.

mandatory_valid_qname(identifier: QualifiedNameCandidate, *, attr: QualifiedName | None = None) → QualifiedName[source]

Resolve an identifier to a qualified name, requiring success.

Parameters:
  • identifier – The candidate to resolve.

  • attr – The attribute the identifier is the value of, named in the message when given (default: None).

Returns:

The resolved QualifiedName.

Raises:

ProvExceptionInvalidQualifiedName – If the identifier cannot be resolved to a valid qualified name. A string or IRI that no namespace resolves carries the sentence saying why.

get_records(class_or_type_or_tuple: type[_R]) → list[_R][source]
get_records(class_or_type_or_tuple: tuple[type, ...] | None = None) → list[ProvRecord]

Return the bundle’s records, optionally filtered by type.

Parameters:

class_or_type_or_tuple – An optional class or tuple of classes; only records passing isinstance() against it are returned (default: None, meaning all records).

Returns:

A new list of the matching ProvRecord objects.

get_record(identifier: QualifiedNameCandidate) → list[ProvRecord][source]

Return all records matching a given identifier.

Parameters:

identifier – The record identifier to look up.

Returns:

The matching ProvRecord objects, or an empty list if the identifier is invalid or unknown.

is_document() → bool[source]

Return True if this is a document, False otherwise.

is_bundle() → bool[source]

Return True if this is a (named) bundle, False otherwise.

has_bundles() → bool[source]

Return True if this object contains bundles, False otherwise.

property bundles: ValuesView[ProvBundle]

The bundles contained in this object.

Raises:

ProvException – Always, since a plain bundle cannot contain sub-bundles. Only ProvDocument overrides this.

get_provn(*, strict: bool = False, width: int | None = 80) → str[source]

Return the PROV-N representation of the bundle.

Parameters:
  • strict – Write output that parses under the strict PROV-N profile, as ProvRecord.get_provn() describes, dropping what alternateOf, specializationOf and hadMember cannot carry there, with a warning each.

  • width – The column limit for one line, as ProvRecord.get_provn() describes, counted with the indentation of the statement. None never wraps.

unified() → ProvBundle[source]

Return a new bundle with records sharing an identifier merged.

Deprecated since version 3.3.0: Unify the document with ProvDocument.unified(), which unifies each bundle in place; 4.0 removes this method.

Unification follows the rules of ProvDocument.unified(). The original bundle is left untouched.

The new bundle belongs to no document. A bundle inside a document gives it the document’s declarations it does not make itself, declared first, so every name resolves to the IRI it has in the original; an IRI both scopes bind is spelled with the document’s prefix.

Returns:

The new, unified ProvBundle.

Raises:

ProvUnificationError – As ProvDocument.unified() raises it, for records of the bundle that cannot be merged.

update(other: ProvBundle) → None[source]

Append all records of another bundle into this bundle.

Parameters:

other – The ProvBundle whose records are appended.

Raises:

ProvException – If other is not a ProvBundle, or is a document that itself contains sub-bundles.

new_record(record_type: QualifiedName, identifier: OptionalID, attributes: RecordAttributesArg | None = None, other_attributes: RecordAttributesArg | None = None) → ProvRecord[source]

Create a new record, add it to the bundle, and return it.

Parameters:
  • record_type – The record type, one of the keys of PROV_REC_CLS.

  • identifier – The identifier for the new record (may be None for relations).

  • attributes – Formal attributes of the record, as a dict or a list of (name, value) pairs (default: None).

  • other_attributes – Additional (non-formal) attributes, in the same forms (default: None).

Returns:

The newly created and added ProvRecord.

Raises:
add_record(record: ProvRecord) → ProvRecord[source]

Add a copy of a record to this bundle.

The record is re-created within this bundle (resolving its identifier and attributes against this bundle’s namespaces), so the returned record is a new object, not record itself.

Parameters:

record – The ProvRecord to copy into the bundle.

Returns:

The newly created ProvRecord belonging to this bundle.

Raises:

ProvMissingFormalAttribute – If record is a hadMember, alternateOf, specializationOf or mentionOf with a party missing.

entity(identifier: QualifiedNameCandidate, other_attributes: RecordAttributesArg | None = None) → ProvEntity[source]

Create a new entity and add it to the bundle.

Parameters:
  • identifier – The identifier for the new entity.

  • other_attributes – Optional attributes for the entity, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvEntity.

activity(identifier: QualifiedNameCandidate, startTime: DatetimeOrStr | None = None, endTime: DatetimeOrStr | None = None, other_attributes: RecordAttributesArg | None = None) → ProvActivity[source]

Create a new activity and add it to the bundle.

Parameters:
  • identifier – The identifier for the new activity.

  • startTime – Optional start time, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • endTime – Optional end time, in the same forms (default: None).

  • other_attributes – Optional attributes for the activity, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvActivity.

generation(entity: EntityRef, activity: ActivityRef | None = None, time: DatetimeOrStr | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvRecord[source]

Create a new generation record for an entity.

Parameters:
  • entity – The generated entity (or its string identifier).

  • activity – The activity (or its string identifier) involved in the generation (default: None).

  • time – Optional time of the generation, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • identifier – Optional identifier for the generation record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new generation record.

usage(activity: ActivityRef, entity: EntityRef | None = None, time: DatetimeOrStr | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvUsage[source]

Create a new usage record for an activity.

Parameters:
  • activity – The using activity (or its string identifier).

  • entity – The entity (or its string identifier) involved in the usage relationship (default: None).

  • time – Optional time of the usage, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • identifier – Optional identifier for the usage record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvUsage record.

start(activity: ActivityRef, trigger: EntityRef | None = None, starter: ActivityRef | None = None, time: DatetimeOrStr | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvStart[source]

Create a new start record for an activity.

Parameters:
  • activity – The started activity (or its string identifier).

  • trigger – The entity (or its string identifier) triggering the start (default: None).

  • starter – Optional activity qualifying the start, through which the trigger entity is generated (default: None).

  • time – Optional time of the start, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • identifier – Optional identifier for the start record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvStart record.

end(activity: ActivityRef, trigger: EntityRef | None = None, ender: ActivityRef | None = None, time: DatetimeOrStr | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvEnd[source]

Create a new end record for an activity.

Parameters:
  • activity – The ended activity (or its string identifier).

  • trigger – The entity (or its string identifier) triggering the end (default: None).

  • ender – Optional activity qualifying the end, through which the trigger entity is generated (default: None).

  • time – Optional time of the end, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • identifier – Optional identifier for the end record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvEnd record.

invalidation(entity: EntityRef, activity: ActivityRef | None = None, time: DatetimeOrStr | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvInvalidation[source]

Create a new invalidation record for an entity.

Parameters:
  • entity – The invalidated entity (or its string identifier).

  • activity – The activity (or its string identifier) involved in the invalidation (default: None).

  • time – Optional time of the invalidation, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • identifier – Optional identifier for the invalidation record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvInvalidation record.

communication(informed: ActivityRef, informant: ActivityRef, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvCommunication[source]

Create a new communication record between two activities.

Parameters:
  • informed – The informed activity (relationship destination).

  • informant – The informing activity (relationship source).

  • identifier – Optional identifier for the communication record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvCommunication record.

agent(identifier: QualifiedNameCandidate, other_attributes: RecordAttributesArg | None = None) → ProvAgent[source]

Create a new agent and add it to the bundle.

Parameters:
  • identifier – The identifier for the new agent.

  • other_attributes – Optional attributes for the agent, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvAgent.

attribution(entity: EntityRef, agent: AgentRef, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvAttribution[source]

Create a new attribution record between an entity and an agent.

Parameters:
  • entity – The entity (or its string identifier) being attributed (relationship source).

  • agent – The agent (or its string identifier) the entity is attributed to (relationship destination).

  • identifier – Optional identifier for the attribution record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvAttribution record.

association(activity: ActivityRef, agent: AgentRef | None = None, plan: EntityRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvAssociation[source]

Create a new association record for an activity.

Parameters:
  • activity – The activity (or its string identifier).

  • agent – The agent (or its string identifier) associated with the activity (default: None).

  • plan – Optional entity qualifying the association through an internal plan (default: None).

  • identifier – Optional identifier for the association record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvAssociation record.

delegation(delegate: AgentRef, responsible: AgentRef, activity: ActivityRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvDelegation[source]

Create a new delegation record between two agents.

Parameters:
  • delegate – The agent (or its string identifier) delegating the responsibility (relationship source).

  • responsible – The agent (or its string identifier) the responsibility is delegated to (relationship destination).

  • activity – Optional activity qualifying the delegation (default: None).

  • identifier – Optional identifier for the delegation record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvDelegation record.

influence(influencee: InfluencerRef, influencer: InfluencerRef, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvInfluence[source]

Create a new influence record between two entities, activities or agents.

Parameters:
  • influencee – The influenced entity, activity or agent (relationship source).

  • influencer – The influencing entity, activity or agent (relationship destination).

  • identifier – Optional identifier for the influence record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvInfluence record.

derivation(generatedEntity: EntityRef, usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvDerivation[source]

Create a new derivation record for a generated entity from a used entity.

Parameters:
  • generatedEntity – The generated entity (or its string identifier), the relationship source.

  • usedEntity – The used entity (or its string identifier), the relationship destination.

  • activity – The activity (or its string identifier) involved in the derivation (default: None).

  • generation – Optional generation record qualifying the derivation through the activity’s generation of the generated entity (default: None).

  • usage – Optional usage record qualifying the derivation through the activity’s use of the used entity (default: None).

  • identifier – Optional identifier for the derivation record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvDerivation record.

revision(generatedEntity: EntityRef, usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvDerivation[source]

Create a new revision record for a generated entity from a used entity.

A revision is a derivation with an additional prov:Revision type.

Parameters:
  • generatedEntity – The generated (revised) entity (or its string identifier), the relationship source.

  • usedEntity – The used (original) entity (or its string identifier), the relationship destination.

  • activity – The activity (or its string identifier) involved in the revision (default: None).

  • generation – Optional generation record qualifying the derivation (default: None).

  • usage – Optional usage record qualifying the derivation (default: None).

  • identifier – Optional identifier for the revision record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvDerivation record, typed as a revision.

quotation(generatedEntity: EntityRef, usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvDerivation[source]

Create a new quotation record for a generated entity from a used entity.

A quotation is a derivation with an additional prov:Quotation type.

Parameters:
  • generatedEntity – The quoting entity (or its string identifier), the relationship source.

  • usedEntity – The quoted entity (or its string identifier), the relationship destination.

  • activity – The activity (or its string identifier) involved in the quotation (default: None).

  • generation – Optional generation record qualifying the derivation (default: None).

  • usage – Optional usage record qualifying the derivation (default: None).

  • identifier – Optional identifier for the quotation record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvDerivation record, typed as a quotation.

primary_source(generatedEntity: EntityRef, usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvDerivation[source]

Create a new primary-source record for a generated entity from a used entity.

A primary source is a derivation with an additional prov:PrimarySource type.

Parameters:
  • generatedEntity – The derived entity (or its string identifier), the relationship source.

  • usedEntity – The primary-source entity (or its string identifier), the relationship destination.

  • activity – The activity (or its string identifier) involved (default: None).

  • generation – Optional generation record qualifying the derivation (default: None).

  • usage – Optional usage record qualifying the derivation (default: None).

  • identifier – Optional identifier for the primary-source record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvDerivation record, typed as a primary source.

specialization(specificEntity: EntityRef, generalEntity: EntityRef) → ProvSpecialization[source]

Create a new specialisation record from a general entity.

Parameters:
  • specificEntity – The specific entity (or its string identifier), the relationship source.

  • generalEntity – The general entity (or its string identifier), the relationship destination.

Returns:

The new ProvSpecialization record.

Raises:

ProvMissingFormalAttribute – If specificEntity or generalEntity is None.

alternate(alternate1: EntityRef, alternate2: EntityRef) → ProvAlternate[source]

Create a new alternate record between two entities.

Parameters:
  • alternate1 – The first entity (or its string identifier), the relationship source.

  • alternate2 – The second entity (or its string identifier), the relationship destination.

Returns:

The new ProvAlternate record.

Raises:

ProvMissingFormalAttribute – If alternate1 or alternate2 is None.

mention(specificEntity: EntityRef, generalEntity: EntityRef, bundle: EntityRef) → ProvMention[source]

Create a new mention record from a general entity in a bundle.

Parameters:
  • specificEntity – The specific entity (or its string identifier), the relationship source.

  • generalEntity – The general entity (or its string identifier), the relationship destination.

  • bundle – The bundle (or its string identifier) that the general entity is described in.

Returns:

The new ProvMention record.

Raises:

ProvMissingFormalAttribute – If specificEntity or generalEntity is None.

collection(identifier: QualifiedNameCandidate, other_attributes: RecordAttributesArg | None = None) → ProvEntity[source]

Create a new collection entity and add it to the bundle.

A collection is an entity with an additional prov:Collection type.

Parameters:
  • identifier – The identifier for the new collection.

  • other_attributes – Optional attributes for the collection, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvEntity, typed as a collection.

membership(collection: EntityRef, entity: EntityRef) → ProvMembership[source]

Create a new membership record adding an entity to a collection.

Parameters:
  • collection – The collection (or its string identifier) the entity is added to.

  • entity – The entity (or its string identifier) added to the collection.

Returns:

The new ProvMembership record.

Raises:

ProvMissingFormalAttribute – If collection or entity is None.

plot(filename: str | bytes | PathLike[str] | None = None, show_nary: bool = True, use_labels: bool = False, show_element_attributes: bool = True, show_relation_attributes: bool = True) → None[source]

Plot the document as a graph, saving to a file or displaying it.

The graph is the one prov.dot.prov_to_dot() draws. A bundle that is not a document warns DeprecationWarning, as prov.dot.prov_to_dot() does, and 4.0 draws documents only.

Parameters:
  • filename – The path to save the plot to, written through Graphviz; the image format is derived from its extension. If not given, the plot is shown through matplotlib, in an interactive window or inline in a notebook (default: None).

  • show_nary – Whether to show all elements in n-ary relations (default: True).

  • use_labels – Whether to label elements by their prov:label property instead of their identifier (default: False).

  • show_element_attributes – Whether to show element attributes (default: True).

  • show_relation_attributes – Whether to show relation attributes (default: True).

Raises:
  • ValueError – If the format implied by filename cannot be saved.

  • ImportError – If no filename is given but matplotlib is not installed.

wasGeneratedBy(entity: EntityRef, activity: ActivityRef | None = None, time: DatetimeOrStr | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvRecord

Create a new generation record for an entity.

Parameters:
  • entity – The generated entity (or its string identifier).

  • activity – The activity (or its string identifier) involved in the generation (default: None).

  • time – Optional time of the generation, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • identifier – Optional identifier for the generation record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new generation record.

used(activity: ActivityRef, entity: EntityRef | None = None, time: DatetimeOrStr | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvUsage

Create a new usage record for an activity.

Parameters:
  • activity – The using activity (or its string identifier).

  • entity – The entity (or its string identifier) involved in the usage relationship (default: None).

  • time – Optional time of the usage, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • identifier – Optional identifier for the usage record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvUsage record.

wasStartedBy(activity: ActivityRef, trigger: EntityRef | None = None, starter: ActivityRef | None = None, time: DatetimeOrStr | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvStart

Create a new start record for an activity.

Parameters:
  • activity – The started activity (or its string identifier).

  • trigger – The entity (or its string identifier) triggering the start (default: None).

  • starter – Optional activity qualifying the start, through which the trigger entity is generated (default: None).

  • time – Optional time of the start, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • identifier – Optional identifier for the start record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvStart record.

wasEndedBy(activity: ActivityRef, trigger: EntityRef | None = None, ender: ActivityRef | None = None, time: DatetimeOrStr | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvEnd

Create a new end record for an activity.

Parameters:
  • activity – The ended activity (or its string identifier).

  • trigger – The entity (or its string identifier) triggering the end (default: None).

  • ender – Optional activity qualifying the end, through which the trigger entity is generated (default: None).

  • time – Optional time of the end, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • identifier – Optional identifier for the end record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvEnd record.

wasInvalidatedBy(entity: EntityRef, activity: ActivityRef | None = None, time: DatetimeOrStr | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvInvalidation

Create a new invalidation record for an entity.

Parameters:
  • entity – The invalidated entity (or its string identifier).

  • activity – The activity (or its string identifier) involved in the invalidation (default: None).

  • time – Optional time of the invalidation, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • identifier – Optional identifier for the invalidation record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvInvalidation record.

wasInformedBy(informed: ActivityRef, informant: ActivityRef, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvCommunication

Create a new communication record between two activities.

Parameters:
  • informed – The informed activity (relationship destination).

  • informant – The informing activity (relationship source).

  • identifier – Optional identifier for the communication record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvCommunication record.

wasAttributedTo(entity: EntityRef, agent: AgentRef, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvAttribution

Create a new attribution record between an entity and an agent.

Parameters:
  • entity – The entity (or its string identifier) being attributed (relationship source).

  • agent – The agent (or its string identifier) the entity is attributed to (relationship destination).

  • identifier – Optional identifier for the attribution record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvAttribution record.

wasAssociatedWith(activity: ActivityRef, agent: AgentRef | None = None, plan: EntityRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvAssociation

Create a new association record for an activity.

Parameters:
  • activity – The activity (or its string identifier).

  • agent – The agent (or its string identifier) associated with the activity (default: None).

  • plan – Optional entity qualifying the association through an internal plan (default: None).

  • identifier – Optional identifier for the association record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvAssociation record.

actedOnBehalfOf(delegate: AgentRef, responsible: AgentRef, activity: ActivityRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvDelegation

Create a new delegation record between two agents.

Parameters:
  • delegate – The agent (or its string identifier) delegating the responsibility (relationship source).

  • responsible – The agent (or its string identifier) the responsibility is delegated to (relationship destination).

  • activity – Optional activity qualifying the delegation (default: None).

  • identifier – Optional identifier for the delegation record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvDelegation record.

wasInfluencedBy(influencee: InfluencerRef, influencer: InfluencerRef, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvInfluence

Create a new influence record between two entities, activities or agents.

Parameters:
  • influencee – The influenced entity, activity or agent (relationship source).

  • influencer – The influencing entity, activity or agent (relationship destination).

  • identifier – Optional identifier for the influence record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvInfluence record.

wasDerivedFrom(generatedEntity: EntityRef, usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvDerivation

Create a new derivation record for a generated entity from a used entity.

Parameters:
  • generatedEntity – The generated entity (or its string identifier), the relationship source.

  • usedEntity – The used entity (or its string identifier), the relationship destination.

  • activity – The activity (or its string identifier) involved in the derivation (default: None).

  • generation – Optional generation record qualifying the derivation through the activity’s generation of the generated entity (default: None).

  • usage – Optional usage record qualifying the derivation through the activity’s use of the used entity (default: None).

  • identifier – Optional identifier for the derivation record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvDerivation record.

wasRevisionOf(generatedEntity: EntityRef, usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvDerivation

Create a new revision record for a generated entity from a used entity.

A revision is a derivation with an additional prov:Revision type.

Parameters:
  • generatedEntity – The generated (revised) entity (or its string identifier), the relationship source.

  • usedEntity – The used (original) entity (or its string identifier), the relationship destination.

  • activity – The activity (or its string identifier) involved in the revision (default: None).

  • generation – Optional generation record qualifying the derivation (default: None).

  • usage – Optional usage record qualifying the derivation (default: None).

  • identifier – Optional identifier for the revision record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvDerivation record, typed as a revision.

wasQuotedFrom(generatedEntity: EntityRef, usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvDerivation

Create a new quotation record for a generated entity from a used entity.

A quotation is a derivation with an additional prov:Quotation type.

Parameters:
  • generatedEntity – The quoting entity (or its string identifier), the relationship source.

  • usedEntity – The quoted entity (or its string identifier), the relationship destination.

  • activity – The activity (or its string identifier) involved in the quotation (default: None).

  • generation – Optional generation record qualifying the derivation (default: None).

  • usage – Optional usage record qualifying the derivation (default: None).

  • identifier – Optional identifier for the quotation record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvDerivation record, typed as a quotation.

hadPrimarySource(generatedEntity: EntityRef, usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, identifier: OptionalID = None, other_attributes: RecordAttributesArg | None = None) → ProvDerivation

Create a new primary-source record for a generated entity from a used entity.

A primary source is a derivation with an additional prov:PrimarySource type.

Parameters:
  • generatedEntity – The derived entity (or its string identifier), the relationship source.

  • usedEntity – The primary-source entity (or its string identifier), the relationship destination.

  • activity – The activity (or its string identifier) involved (default: None).

  • generation – Optional generation record qualifying the derivation (default: None).

  • usage – Optional usage record qualifying the derivation (default: None).

  • identifier – Optional identifier for the primary-source record (default: None).

  • other_attributes – Optional extra attributes, as a dict or a list of (name, value) pairs (default: None).

Returns:

The new ProvDerivation record, typed as a primary source.

alternateOf(alternate1: EntityRef, alternate2: EntityRef) → ProvAlternate

Create a new alternate record between two entities.

Parameters:
  • alternate1 – The first entity (or its string identifier), the relationship source.

  • alternate2 – The second entity (or its string identifier), the relationship destination.

Returns:

The new ProvAlternate record.

Raises:

ProvMissingFormalAttribute – If alternate1 or alternate2 is None.

specializationOf(specificEntity: EntityRef, generalEntity: EntityRef) → ProvSpecialization

Create a new specialisation record from a general entity.

Parameters:
  • specificEntity – The specific entity (or its string identifier), the relationship source.

  • generalEntity – The general entity (or its string identifier), the relationship destination.

Returns:

The new ProvSpecialization record.

Raises:

ProvMissingFormalAttribute – If specificEntity or generalEntity is None.

mentionOf(specificEntity: EntityRef, generalEntity: EntityRef, bundle: EntityRef) → ProvMention

Create a new mention record from a general entity in a bundle.

Parameters:
  • specificEntity – The specific entity (or its string identifier), the relationship source.

  • generalEntity – The general entity (or its string identifier), the relationship destination.

  • bundle – The bundle (or its string identifier) that the general entity is described in.

Returns:

The new ProvMention record.

Raises:

ProvMissingFormalAttribute – If specificEntity or generalEntity is None.

hadMember(collection: EntityRef, entity: EntityRef) → ProvMembership

Create a new membership record adding an entity to a collection.

Parameters:
  • collection – The collection (or its string identifier) the entity is added to.

  • entity – The entity (or its string identifier) added to the collection.

Returns:

The new ProvMembership record.

Raises:

ProvMissingFormalAttribute – If collection or entity is None.

Records

Every statement is a ProvRecord. Elements and relations share its attribute, comparison and PROV-N methods, so those are documented once here.

class prov.model.ProvRecord(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: object

Base class for PROV records.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = ()

Formal attributes names of this record type, in the expected order.

copy() → ProvRecord[source]

Return an exact copy of this record.

get_type() → QualifiedName[source]

Return the PROV type of the record.

Raises:

NotImplementedError – If the record type is undefined (i.e. on the abstract base classes).

get_asserted_types() → set[QualifiedName][source]

Return the set of all asserted PROV types of this record.

Returns a fresh, plain set copy, so mutating it does not affect the record. The set holds the prov:type values as asserted, whether QualifiedNames, strings, numbers or other attribute values, although the annotation says QualifiedName (#748). Values that Python holds equal collapse in it, as get_attribute() describes.

add_asserted_type(type_identifier: QualifiedName) → None[source]

Add a PROV type assertion to the record.

Parameters:

type_identifier – The qualified name of the type to assert.

get_attribute(attr_name: QualifiedNameCandidate) → set[Any][source]

Return the values (if any) for the named attribute.

Parameters:

attr_name – The name of the attribute.

Returns:

A fresh, plain set copy of the values held for the attribute (empty if none); mutating it does not affect the record. Values that Python holds equal but that differ in type, such as 2 and 2.0, collapse in this copy to whichever was asserted first. The record keeps both, and attributes, extra_attributes, equality, hashing and serialisation all see both.

Raises:

ProvExceptionInvalidQualifiedName – If attr_name cannot be resolved to a valid qualified name.

property identifier: QualifiedName | None

The record’s identifier, or None if it has none.

property attributes: list[tuple[QualifiedName, Any]]

All of the record’s attributes as a list of (name, value) pairs.

Attributes with multiple values appear once per value, so the same name may occur more than once.

property args: tuple[Any, ...]

The values of the record’s formal attributes, in declaration order.

Missing formal attributes are represented by None.

property formal_attributes: tuple[tuple[QualifiedName, Any], ...]

The record’s formal attributes as (name, value) pairs.

Pairs are in declaration order; a missing attribute has a value of None.

property extra_attributes: tuple[tuple[QualifiedName, Any], ...]

The record’s non-formal attributes as (name, value) pairs.

property bundle: ProvBundle

The bundle that owns this record.

Deprecated since version 3.3.0: 4.0 removes this property. Keep the document or bundle that made the record beside it. With only the document, test the record with is against the document’s own ProvBundle.records and against the ProvBundle.records of each bundle in ProvDocument.bundles. A record found in none of them belongs to another container.

property label: str

The record’s identifying label.

This is the record’s prov:label attribute if set, otherwise its identifier.

property value: set[Any]

The set of the record’s prov:value attribute values.

Returns a fresh, plain set copy. get_attribute() describes how it treats prov:value values that Python holds equal but that differ in type.

add_attributes(attributes: RecordAttributesArg) → None[source]

Add attributes to the record.

Attribute names are resolved to qualified names, and values are normalised to the datatype expected for the attribute. None values are skipped.

Parameters:

attributes – The attributes to add, as a mapping keyed by qualified-name identifiers, or as a sequence, set or iterator of (name, value) pairs whose names satisfy the same condition.

Raises:
  • ProvExceptionInvalidQualifiedName – If an attribute name cannot be resolved to a valid qualified name, or a value typed as a qualified name does not resolve by its prefix.

  • ProvException – If a value is invalid for its attribute, or a second, different value is supplied for a single-valued attribute.

get_provn(strict: bool = False, width: int | None = 80) → str[source]

Return the PROV-N representation of the record.

A statement with an attribute block that is wider than width columns is written over several lines. The keyword, identifier and formal arguments stay on the first line and the attribute block follows, one name=value pair per line, aligned after the opening parenthesis. The formal arguments and a single pair are never broken. str(record) never wraps. A string value that holds a line feed is still written as a triple-quoted string over several lines. A subclass that overrides this method takes width too, because the PROV-N writer passes it.

Parameters:
  • strict – Write output that parses under the strict PROV-N profile. Mention is written prov:mentionOf instead of the bare mentionOf keyword, and alternateOf, specializationOf and hadMember are written without the identifier or attribute block PROV-N does not give them, each dropped with a ProvWarning that names the record.

  • width – The column limit for one line. None never wraps. A width of 0 or less wraps every statement that has an attribute block.

is_element() → bool[source]

Return True if the record is an element, False otherwise.

is_relation() → bool[source]

Return True if the record is a relation, False otherwise.

class prov.model.ProvElement(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRecord

Provenance Element (nodes in the provenance graph).

property identifier: QualifiedName

The element’s identifier. Every element has one.

is_element() → bool[source]

Return True if the record is an element, False otherwise.

class prov.model.ProvRelation(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRecord

Provenance Relationship (edge between nodes).

is_relation() → bool[source]

Return True if the record is a relation, False otherwise.

Elements

class prov.model.ProvEntity(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvElement

Provenance Entity element

wasGeneratedBy(activity: ActivityRef | None = None, time: DatetimeOrStr | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new generation record to this entity.

Parameters:
  • activity – The activity (or its string identifier) involved in the generation (default: None).

  • time – Optional time of the generation, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This entity (to allow chaining).

wasInvalidatedBy(activity: ActivityRef | None, time: DatetimeOrStr | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new invalidation record for this entity.

Parameters:
  • activity – The activity (or its string identifier) involved in the invalidation; may be None.

  • time – Optional time of the invalidation, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This entity (to allow chaining).

wasDerivedFrom(usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new derivation record for this entity from a used entity.

Parameters:
  • usedEntity – The used entity (or its string identifier).

  • activity – The activity (or its string identifier) involved in the derivation (default: None).

  • generation – Optional generation record qualifying the derivation through an internal generation (default: None).

  • usage – Optional usage record qualifying the derivation through an internal usage (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This entity (to allow chaining).

wasAttributedTo(agent: AgentRef, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new attribution record between this entity and an agent.

Parameters:
  • agent – The agent (or its string identifier) involved in the attribution.

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This entity (to allow chaining).

alternateOf(alternate2: EntityRef) → Self[source]

Create a new alternate record between this and another entity.

Parameters:

alternate2 – The other entity (or its string identifier).

Returns:

This entity (to allow chaining).

Raises:

ProvMissingFormalAttribute – If alternate2 is None.

specializationOf(generalEntity: EntityRef) → Self[source]

Create a new specialisation record for this from a general entity.

Parameters:

generalEntity – The general entity (or its string identifier).

Returns:

This entity (to allow chaining).

Raises:

ProvMissingFormalAttribute – If generalEntity is None.

hadMember(entity: EntityRef) → Self[source]

Create a new membership record adding an entity to this collection.

Parameters:

entity – The entity (or its string identifier) to add to the collection.

Returns:

This entity (to allow chaining).

Raises:

ProvMissingFormalAttribute – If entity is None.

wasRevisionOf(usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new revision record for this entity from a used entity.

Parameters:
  • usedEntity – The original entity (or its string identifier).

  • activity – The activity (or its string identifier) involved in the revision (default: None).

  • generation – Optional generation record qualifying the derivation (default: None).

  • usage – Optional usage record qualifying the derivation (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This entity (to allow chaining).

wasQuotedFrom(usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new quotation record for this entity from a quoted entity.

Parameters:
  • usedEntity – The quoted entity (or its string identifier).

  • activity – The activity (or its string identifier) involved in the quotation (default: None).

  • generation – Optional generation record qualifying the derivation (default: None).

  • usage – Optional usage record qualifying the derivation (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This entity (to allow chaining).

hadPrimarySource(usedEntity: EntityRef, activity: ActivityRef | None = None, generation: GenerationRef | None = None, usage: UsageRef | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new primary-source record for this entity.

Parameters:
  • usedEntity – The primary-source entity (or its string identifier).

  • activity – The activity (or its string identifier) involved (default: None).

  • generation – Optional generation record qualifying the derivation (default: None).

  • usage – Optional usage record qualifying the derivation (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This entity (to allow chaining).

mentionOf(generalEntity: EntityRef, bundle: EntityRef) → Self[source]

Create a new mention record of this entity from a general entity.

Parameters:
  • generalEntity – The general entity (or its string identifier), the relationship destination.

  • bundle – The bundle (or its string identifier) that the general entity is described in.

Returns:

This entity (to allow chaining).

Raises:

ProvMissingFormalAttribute – If generalEntity is None.

wasInfluencedBy(influencer: InfluencerRef, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new influence record on this entity by an influencer.

Parameters:
  • influencer – The influencing entity, activity or agent (or its string identifier).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This entity (to allow chaining).

class prov.model.ProvActivity(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvElement

Provenance Activity element.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:startTime>, <QualifiedName: prov:endTime>)

Formal attributes names of this record type, in the expected order.

set_time(startTime: datetime | None = None, endTime: datetime | None = None) → None[source]

Set the start and/or end time of this activity.

Only non-None arguments are applied; the values are stored as given (no string parsing is performed here).

Parameters:
get_startTime() → datetime | None[source]

Return the activity’s start time, or None if unset.

get_endTime() → datetime | None[source]

Return the activity’s end time, or None if unset.

used(entity: EntityRef, time: DatetimeOrStr | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new usage record for this activity.

Parameters:
  • entity – The entity (or its string identifier) involved in the usage relationship.

  • time – Optional time of the usage, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This activity (to allow chaining).

wasInformedBy(informant: ActivityRef, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new communication record for this activity.

Parameters:
  • informant – The informing activity (relationship source).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This activity (to allow chaining).

wasStartedBy(trigger: EntityRef | None, starter: ActivityRef | None = None, time: DatetimeOrStr | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new start record for this activity.

The activity did not exist before being started by the trigger.

Parameters:
  • trigger – The entity triggering the start of this activity; may be None.

  • starter – Optional activity qualifying the start, through which the trigger entity is generated (default: None).

  • time – Optional time of the start, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This activity (to allow chaining).

wasEndedBy(trigger: EntityRef | None, ender: ActivityRef | None = None, time: DatetimeOrStr | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new end record for this activity.

Parameters:
  • trigger – The entity triggering the end of this activity; may be None.

  • ender – Optional activity qualifying the end, through which the trigger entity is generated (default: None).

  • time – Optional time of the end, as a datetime.datetime or an xsd:dateTime string accepted by parse_xsd_datetime() (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This activity (to allow chaining).

wasAssociatedWith(agent: AgentRef, plan: EntityRef | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new association record for this activity.

Parameters:
  • agent – The agent (or its string identifier) involved in the association.

  • plan – Optional entity qualifying the association through an internal plan (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This activity (to allow chaining).

wasInfluencedBy(influencer: InfluencerRef, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new influence record on this activity by an influencer.

Parameters:
  • influencer – The influencing entity, activity or agent (or its string identifier).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This activity (to allow chaining).

class prov.model.ProvAgent(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvElement

Provenance Agent element.

actedOnBehalfOf(responsible: AgentRef, activity: ActivityRef | None = None, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new delegation record on behalf of this agent.

Parameters:
  • responsible – The agent (or its string identifier) that the responsibility is delegated to.

  • activity – Optional activity qualifying the delegation (default: None).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This agent (to allow chaining).

wasInfluencedBy(influencer: InfluencerRef, attributes: RecordAttributesArg | None = None) → Self[source]

Create a new influence record on this agent by an influencer.

Parameters:
  • influencer – The influencing entity, activity or agent (or its string identifier).

  • attributes – Optional extra attributes for the record, as a dict or a list of (name, value) pairs (default: None).

Returns:

This agent (to allow chaining).

Relations

class prov.model.ProvGeneration(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Generation relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:entity>, <QualifiedName: prov:activity>, <QualifiedName: prov:time>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvUsage(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Usage relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:activity>, <QualifiedName: prov:entity>, <QualifiedName: prov:time>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvCommunication(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Communication relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:informed>, <QualifiedName: prov:informant>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvStart(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Start relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:activity>, <QualifiedName: prov:trigger>, <QualifiedName: prov:starter>, <QualifiedName: prov:time>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvEnd(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance End relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:activity>, <QualifiedName: prov:trigger>, <QualifiedName: prov:ender>, <QualifiedName: prov:time>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvInvalidation(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Invalidation relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:entity>, <QualifiedName: prov:activity>, <QualifiedName: prov:time>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvDerivation(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Derivation relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:generatedEntity>, <QualifiedName: prov:usedEntity>, <QualifiedName: prov:activity>, <QualifiedName: prov:generation>, <QualifiedName: prov:usage>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvAttribution(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Attribution relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:entity>, <QualifiedName: prov:agent>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvAssociation(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Association relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:activity>, <QualifiedName: prov:agent>, <QualifiedName: prov:plan>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvDelegation(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Delegation relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:delegate>, <QualifiedName: prov:responsible>, <QualifiedName: prov:activity>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvInfluence(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Influence relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:influencee>, <QualifiedName: prov:influencer>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvSpecialization(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Specialization relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:specificEntity>, <QualifiedName: prov:generalEntity>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvAlternate(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Alternate relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:alternate1>, <QualifiedName: prov:alternate2>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvMention(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvSpecialization

Provenance Mention relationship (specific Specialization).

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:specificEntity>, <QualifiedName: prov:generalEntity>, <QualifiedName: prov:bundle>)

Formal attributes names of this record type, in the expected order.

class prov.model.ProvMembership(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]

Bases: ProvRelation

Provenance Membership relationship.

FORMAL_ATTRIBUTES: tuple[QualifiedName, ...] = (<QualifiedName: prov:collection>, <QualifiedName: prov:entity>)

Formal attributes names of this record type, in the expected order.

Namespaces and literals

class prov.model.NamespaceManager(namespaces: NSCollection | None = None, default: str | None = None, parent: NamespaceManager | None = None)[source]

Bases: dict[str, Namespace]

Manages namespaces for PROV documents and bundles.

Register namespaces through add_namespace() and set_default_namespace(). Any of the dict’s own write methods bypasses the manager’s indexes and is unsupported.

parent: NamespaceManager | None = None

Parent NamespaceManager this manager is a child of, if any.

get_namespace(uri: str) → Namespace | None[source]

Return the known namespace with the given URI.

Lookup is by index, not by scan. When more than one known namespace has the URI, the built-in prov and xsd namespaces win, then the explicitly registered namespace, then the default namespace.

Parameters:

uri – The namespace URI to look up.

Returns:

The matching Namespace, or None if no known namespace has that URI.

get_registered_namespaces() → Iterable[Namespace][source]

Return all explicitly registered namespaces.

Returns:

An iterable of Namespace. This excludes the default namespaces (prov and xsd).

set_default_namespace(uri: str) → None[source]

Set the default namespace to one with the given URI.

Parameters:

uri – The URI of the default namespace.

Raises:

ProvValueError – If uri is blank or starts with @.

get_default_namespace() → Namespace | None[source]

Return the default namespace, or None if none is set.

add_namespace(namespace: Namespace) → Namespace[source]

Add a namespace, unless an equivalent one is already registered.

If a namespace with the same URI already exists, that existing namespace is returned. If the prefix conflicts with a different namespace, the added namespace is renamed to an unused prefix.

Parameters:

namespace – The Namespace to add.

Returns:

The registered namespace, which may be the existing or renamed one rather than the argument.

Raises:

ProvException – If namespace is a default namespace, which only set_default_namespace() declares.

add_namespaces(namespaces: NSCollection) → None[source]

Add multiple namespaces into this manager.

Parameters:

namespaces – The namespaces to add, as a {prefix: uri} mapping or an iterable of Namespace.

Raises:
  • ProvValueError – If a mapping has an empty prefix, a prefix that is not a PN_PREFIX, or a blank IRI or one that starts with @.

  • ProvException – If an iterable holds a default namespace.

valid_qualified_name(qname: QualifiedNameCandidate) → QualifiedName | None[source]

Resolve an identifier to a valid qualified name.

Registers the namespace of the resolved name if it was not registered already. Where the identifier is a string or Identifier, an attempt is made to expand a prefix declared here, or, when no enclosing scope declares the prefix, to compact a known namespace URI, delegating to the parent manager if all local attempts fail.

Parameters:

qname – The candidate to resolve, as a QualifiedName, Identifier, or string.

Returns:

The resolved QualifiedName, or None if it could not be resolved.

lookup(prefix: str, local: str) → QualifiedName | None[source]

Resolve a name a reader has already split at its first :.

The name is minted from the namespace the nearest scope binds prefix to, the nearest default namespace for an empty prefix. Nothing is compacted, registered or cached. ("", "") and the blank-node prefix _ resolve to nothing whatever is declared.

Parameters:
  • prefix – The prefix before the first :, "" for none.

  • local – The local part after it.

Returns:

The QualifiedName, or None when no scope binds prefix.

get_anonymous_identifier(local_prefix: str = 'id') → Identifier[source]

Return a fresh anonymous (blank-node) identifier.

Each call increments an internal counter, so successive calls return distinct identifiers.

Parameters:

local_prefix – Prefix for the local part of the identifier (default: "id").

Returns:

A new Identifier of the form _:<local_prefix><n>.

class prov.model.Literal(value: Any, datatype: QualifiedName | None = None, langtag: str | None = None)[source]

Bases: object

A typed (and optionally language-tagged) PROV literal value.

A literal pairs a string value with an optional datatype and an optional language tag. Supplying a language tag forces the datatype to prov:InternationalizedString, to comply with the PROV-JSON/PROV-XML rules for language-tagged strings. If no datatype was given, that one is assumed. Any other datatype is overridden, and the constructor logs a warning.

Its fields are read-only after construction. Assigning or deleting one raises AttributeError, while a subclass may still set attributes of its own.

property value: str

The literal’s value as a string.

property datatype: QualifiedName | None

The literal’s datatype, or None if it has none.

property langtag: str | None

The literal’s language tag, or None if it has none.

has_no_langtag() → bool[source]

Return True if the literal has no language tag.

provn_representation() → str[source]

Return the PROV-N representation of the literal, the datatype spelled as at an identifier position, so a : in its local part is escaped.

Type aliases

The signatures above name these aliases. AttributeValue is the type of the values a dict of attributes may hold; Type-check code that uses prov shows how to use it when a type checker reports a call.

prov.model.AttributeValue

A value accepted for a record attribute, before coercion. Python values lists what each type becomes. alias of ProvRecord | QualifiedName | Identifier | datetime | Literal | str | float | int | bool | None | Decimal | date | time | timedelta | UUID | bytes | bytearray | memoryview

prov.model.RecordAttributesArg

The attributes of a record: a mapping from attribute name to value, or pairs of name and value in a sequence, a set or an iterator. alias of _SupportsItems[QualifiedName | str | Identifier, ProvRecord | QualifiedName | Identifier | datetime | Literal | str | float | int | bool | None | Decimal | date | time | timedelta | UUID | bytes | bytearray | memoryview] | Sequence[tuple[QualifiedName | str | Identifier, Any]] | Set[tuple[QualifiedName | str | Identifier, Any]] | Iterator[tuple[QualifiedName | str | Identifier, Any]]

prov.model.OptionalID

An identifier as a qualified name, a string or an Identifier, or None.

prov.model.EntityRef

An entity, or its identifier as a qualified name, a string or an Identifier. alias of ProvEntity | QualifiedName | str | Identifier

prov.model.ActivityRef

An activity, or its identifier. alias of ProvActivity | QualifiedName | str | Identifier

prov.model.AgentRef

An agent, or an entity or activity acting as one, or its identifier. alias of ProvAgent | ProvEntity | ProvActivity | QualifiedName | str | Identifier

prov.model.InfluencerRef

Any element, or its identifier. alias of ProvEntity | QualifiedName | str | Identifier | ProvActivity | ProvAgent

prov.model.GenerationRef

A generation record, or its identifier. alias of ProvGeneration | QualifiedName | str | Identifier

prov.model.UsageRef

A usage record, or its identifier. alias of ProvUsage | QualifiedName | str | Identifier

prov.model.StreamOrPath

An open stream, or a path as a string, bytes or os.PathLike. alias of IOBase | IO[Any] | str | bytes | PathLike[str]

prov.model.QualifiedNameCandidate

A qualified name, or a string or Identifier the bundle resolves to one.

prov.model.DatetimeOrStr

A datetime, or an xsd:dateTime string parsed with parse_xsd_datetime().

prov.model.NSCollection

Namespaces to register: a mapping from prefix to URI, or Namespace objects.

Functions and tables

prov.model.parse_xsd_datetime(value: str) → datetime | None[source]

Parse an xsd:dateTime string into a datetime.datetime.

Accepts the xsd:dateTime lexical space, as XSD 1.1 defines it, and nothing else. That is a date, T, a time with up to six fractional digits, and Z or an hh:mm offset. The hour-24 end-of-day form maps to 00:00:00 of the following day, per the XSD value space. Text in another ISO 8601 form, such as 2012-12-03T21:08Z or a week date, a bare xsd:date, and a fraction of more than six digits, which a datetime.datetime cannot hold, are not accepted.

Parameters:

value – The date/time string to parse.

Returns:

The parsed datetime, or None if value could not be parsed.

prov.model.PROV_REC_CLS

Maps each record type to the class that represents it; the lookup new_record() and the deserializers use.

Exceptions

prov.serializers shows how these classes and the serialisation errors relate.

class prov.Error[source]

Bases: Exception

Base class for all errors in this package.

class prov.model.ProvException[source]

Bases: Error

Base class for PROV model exceptions.

class prov.model.ProvWarning[source]

Bases: Warning

Base class for PROV model warnings.

class prov.model.ProvFutureRejectionWarning[source]

Bases: ProvWarning

A warning that prov never raises.

The class stays importable so that a filter written for 3.2.3, such as warnings.simplefilter("error", ProvFutureRejectionWarning), keeps working. 4.0 removes it.

class prov.model.ProvExceptionInvalidQualifiedName(qname: Any, detail: str | None = None)[source]

Bases: ProvException

Exception for an invalid qualified identifier name.

qname = None

The invalid qualified name that triggered the exception.

detail: str | None = None

What is wrong with it, when the name itself does not say.

class prov.model.ProvElementIdentifierRequired[source]

Bases: ProvException

Exception for a missing element identifier.

class prov.model.ProvMissingFormalAttribute[source]

Bases: ProvException

Exception for a relation missing a party it requires.

hadMember, alternateOf, specializationOf and mentionOf refuse a record that lacks an entity or a collection. mentionOf may omit its bundle.

class prov.model.ProvValueError[source]

Bases: ProvException, ValueError

A value a Literal or an attribute cannot hold, or a namespace prefix or IRI the model refuses.

Raised at assertion for a time whose offset is beyond ±14:00, and when a Literal is built with a language tag that is empty or not shaped like a BCP 47 tag. A subclass of both ProvException and ValueError, so a caller can catch either.

class prov.model.ProvUnificationError[source]

Bases: ProvException

Raised by ProvDocument.unified() when records sharing an identifier cannot be merged under PROV-CONSTRAINTS term unification (two different concrete values for the same formal attribute, an absent value in a non-expandable position against a present one, or records of incompatible types).