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:
ProvBundleThe top-level container of a PROV document.
A document holds records and named bundles.
serialize()writes one, andprov.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 warnsDeprecationWarning, asprov.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:labelproperty 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
filenamecannot be saved.ImportError – If no
filenameis given but matplotlib is not installed.
- 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
otherare 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
ProvDocumentorProvBundlewhose records are appended.- Raises:
ProvException – If
otheris not aProvBundle(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
ProvBundleto add.identifier – Optional identifier to use for the bundle; if not given, the bundle’s own identifier is used (default:
None).
- Raises:
ProvException – If
bundleis not aProvBundle, is a document with nested bundles, has no usable identifier, or an identifier collides with an existing bundle, orbundlealready 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:
ProvException – If
identifierisNoneor a bundle with that identifier already exists.ProvExceptionInvalidQualifiedName – If no namespace resolves
identifier.
- 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"(seeprov.serializers.get()).- Parameters:
destination – A writable stream (any object with a
writemethod) or a local file path to write to. IfNone, the serialization is returned as a string (default:None). A non-local (network) location is not written and yieldsNone.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
destinationwas given, otherwiseNone.
- 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
sourceorcontentshould be given;contenttakes precedence if both are.- Parameters:
source – A readable stream (any object with a
readmethod) or a file path to read from (default:None).content – The document as a
strorbytesto 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
sourcenorcontentis 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:
objectA 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.
ProvDocumentis the subclass that also holds bundles.- property document: ProvDocument | None¶
The parent document of this bundle, or
Noneif it has none.Deprecated since version 3.3.0: Keep a reference to the
ProvDocumentthat holds the bundle; 4.0 removes this property.
- property identifier: QualifiedName | None¶
The bundle’s identifier, or
Noneif 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
uriis 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
Noneif 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
Namespaceto add, or a prefix string (in which caseuriis required).uri – The namespace URI; required when
namespace_or_prefixis 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 whoseuriis 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, orNoneif 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
ProvRecordobjects.
- 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
ProvRecordobjects, or an empty list if the identifier is invalid or unknown.
- property bundles: ValuesView[ProvBundle]¶
The bundles contained in this object.
- Raises:
ProvException – Always, since a plain bundle cannot contain sub-bundles. Only
ProvDocumentoverrides 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 whatalternateOf,specializationOfandhadMembercannot 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.Nonenever 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
ProvBundlewhose records are appended.- Raises:
ProvException – If
otheris not aProvBundle, 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
Nonefor 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:
ProvExceptionInvalidQualifiedName – If
identifieris set and no namespace resolves it.ProvMissingFormalAttribute – If
record_typeis ahadMember,alternateOf,specializationOformentionOfandattributesleave a party without a value.
- 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
recorditself.- Parameters:
record – The
ProvRecordto copy into the bundle.- Returns:
The newly created
ProvRecordbelonging to this bundle.- Raises:
ProvMissingFormalAttribute – If
recordis ahadMember,alternateOf,specializationOformentionOfwith 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.datetimeor anxsd:dateTimestring accepted byparse_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.datetimeor anxsd:dateTimestring accepted byparse_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.datetimeor anxsd:dateTimestring accepted byparse_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
ProvUsagerecord.
- 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.datetimeor anxsd:dateTimestring accepted byparse_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
ProvStartrecord.
- 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.datetimeor anxsd:dateTimestring accepted byparse_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
ProvEndrecord.
- 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.datetimeor anxsd:dateTimestring accepted byparse_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
ProvInvalidationrecord.
- 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
ProvCommunicationrecord.
- 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
ProvAttributionrecord.
- 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
ProvAssociationrecord.
- 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
ProvDelegationrecord.
- 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
ProvInfluencerecord.
- 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
ProvDerivationrecord.
- 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:Revisiontype.- 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
ProvDerivationrecord, 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:Quotationtype.- 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
ProvDerivationrecord, 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:PrimarySourcetype.- 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
ProvDerivationrecord, 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
ProvSpecializationrecord.- Raises:
ProvMissingFormalAttribute – If
specificEntityorgeneralEntityisNone.
- 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
ProvAlternaterecord.- Raises:
ProvMissingFormalAttribute – If
alternate1oralternate2isNone.
- 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
ProvMentionrecord.- Raises:
ProvMissingFormalAttribute – If
specificEntityorgeneralEntityisNone.
- 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:Collectiontype.- 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
ProvMembershiprecord.- Raises:
ProvMissingFormalAttribute – If
collectionorentityisNone.
- 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 warnsDeprecationWarning, asprov.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:labelproperty 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
filenamecannot be saved.ImportError – If no
filenameis 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.datetimeor anxsd:dateTimestring accepted byparse_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.datetimeor anxsd:dateTimestring accepted byparse_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
ProvUsagerecord.
- 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.datetimeor anxsd:dateTimestring accepted byparse_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
ProvStartrecord.
- 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.datetimeor anxsd:dateTimestring accepted byparse_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
ProvEndrecord.
- 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.datetimeor anxsd:dateTimestring accepted byparse_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
ProvInvalidationrecord.
- 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
ProvCommunicationrecord.
- 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
ProvAttributionrecord.
- 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
ProvAssociationrecord.
- 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
ProvDelegationrecord.
- 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
ProvInfluencerecord.
- 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
ProvDerivationrecord.
- 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:Revisiontype.- 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
ProvDerivationrecord, 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:Quotationtype.- 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
ProvDerivationrecord, 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:PrimarySourcetype.- 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
ProvDerivationrecord, 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
ProvAlternaterecord.- Raises:
ProvMissingFormalAttribute – If
alternate1oralternate2isNone.
- 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
ProvSpecializationrecord.- Raises:
ProvMissingFormalAttribute – If
specificEntityorgeneralEntityisNone.
- 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
ProvMentionrecord.- Raises:
ProvMissingFormalAttribute – If
specificEntityorgeneralEntityisNone.
- 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
ProvMembershiprecord.- Raises:
ProvMissingFormalAttribute – If
collectionorentityisNone.
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:
objectBase 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
setcopy, so mutating it does not affect the record. The set holds theprov:typevalues as asserted, whetherQualifiedNames, strings, numbers or other attribute values, although the annotation saysQualifiedName(#748). Values that Python holds equal collapse in it, asget_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
setcopy 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 as2and2.0, collapse in this copy to whichever was asserted first. The record keeps both, andattributes,extra_attributes, equality, hashing and serialisation all see both.- Raises:
ProvExceptionInvalidQualifiedName – If
attr_namecannot be resolved to a valid qualified name.
- property identifier: QualifiedName | None¶
The record’s identifier, or
Noneif 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
isagainst the document’s ownProvBundle.recordsand against theProvBundle.recordsof each bundle inProvDocument.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:labelattribute if set, otherwise its identifier.
- property value: set[Any]¶
The set of the record’s
prov:valueattribute values.Returns a fresh, plain
setcopy.get_attribute()describes how it treatsprov:valuevalues 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.
Nonevalues 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
widthcolumns is written over several lines. The keyword, identifier and formal arguments stay on the first line and the attribute block follows, onename=valuepair 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 takeswidthtoo, because the PROV-N writer passes it.- Parameters:
strict – Write output that parses under the strict PROV-N profile. Mention is written
prov:mentionOfinstead of the barementionOfkeyword, andalternateOf,specializationOfandhadMemberare written without the identifier or attribute block PROV-N does not give them, each dropped with aProvWarningthat names the record.width – The column limit for one line.
Nonenever wraps. A width of0or less wraps every statement that has an attribute block.
- class prov.model.ProvElement(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]¶
Bases:
ProvRecordProvenance Element (nodes in the provenance graph).
- property identifier: QualifiedName¶
The element’s identifier. Every element has one.
- class prov.model.ProvRelation(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]¶
Bases:
ProvRecordProvenance Relationship (edge between nodes).
Elements¶
- class prov.model.ProvEntity(bundle: ProvBundle, identifier: QualifiedName | None, attributes: RecordAttributesArg | None = None)[source]¶
Bases:
ProvElementProvenance 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.datetimeor anxsd:dateTimestring accepted byparse_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.datetimeor anxsd:dateTimestring accepted byparse_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
alternate2isNone.
- 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
generalEntityisNone.
- 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
entityisNone.
- 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
generalEntityisNone.
- 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:
ProvElementProvenance 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-
Nonearguments are applied; the values are stored as given (no string parsing is performed here).- Parameters:
startTime – The start time as a
datetime.datetime(default:None).endTime – The end time as a
datetime.datetime(default:None).
- 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.datetimeor anxsd:dateTimestring accepted byparse_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.datetimeor anxsd:dateTimestring accepted byparse_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.datetimeor anxsd:dateTimestring accepted byparse_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:
ProvElementProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvRelationProvenance 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:
ProvSpecializationProvenance 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:
ProvRelationProvenance 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]¶
-
Manages namespaces for PROV documents and bundles.
Register namespaces through
add_namespace()andset_default_namespace(). Any of the dict’s own write methods bypasses the manager’s indexes and is unsupported.- parent: NamespaceManager | None = None¶
Parent
NamespaceManagerthis 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
provandxsdnamespaces win, then the explicitly registered namespace, then the default namespace.- Parameters:
uri – The namespace URI to look up.
- Returns:
The matching
Namespace, orNoneif 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 (provandxsd).
- 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
uriis blank or starts with@.
- get_default_namespace() Namespace | None[source]¶
Return the default namespace, or
Noneif 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
Namespaceto add.- Returns:
The registered namespace, which may be the existing or renamed one rather than the argument.
- Raises:
ProvException – If
namespaceis a default namespace, which onlyset_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 ofNamespace.- 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, orNoneif 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
prefixto, 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, orNonewhen no scope bindsprefix.
- 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
Identifierof the form_:<local_prefix><n>.
- class prov.model.Literal(value: Any, datatype: QualifiedName | None = None, langtag: str | None = None)[source]¶
Bases:
objectA 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 datatype: QualifiedName | None¶
The literal’s datatype, or
Noneif it has none.
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, orNone.
- prov.model.EntityRef¶
An entity, or its identifier as a qualified name, a string or an
Identifier. alias ofProvEntity|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 ofIOBase|IO[Any] |str|bytes|PathLike[str]
- prov.model.QualifiedNameCandidate¶
A qualified name, or a string or
Identifierthe bundle resolves to one.
- prov.model.DatetimeOrStr¶
A
datetime, or anxsd:dateTimestring parsed withparse_xsd_datetime().
- prov.model.NSCollection¶
Namespaces to register: a mapping from prefix to URI, or
Namespaceobjects.
Functions and tables¶
- prov.model.parse_xsd_datetime(value: str) datetime | None[source]¶
Parse an
xsd:dateTimestring into adatetime.datetime.Accepts the
xsd:dateTimelexical space, as XSD 1.1 defines it, and nothing else. That is a date,T, a time with up to six fractional digits, andZor anhh:mmoffset. 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 as2012-12-03T21:08Zor a week date, a barexsd:date, and a fraction of more than six digits, which adatetime.datetimecannot hold, are not accepted.- Parameters:
value – The date/time string to parse.
- Returns:
The parsed
datetime, orNoneifvaluecould 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.model.ProvFutureRejectionWarning[source]¶
Bases:
ProvWarningA warning that
provnever 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:
ProvExceptionException for an invalid qualified identifier name.
- qname = None¶
The invalid qualified name that triggered the exception.
- class prov.model.ProvElementIdentifierRequired[source]¶
Bases:
ProvExceptionException for a missing element identifier.
- class prov.model.ProvMissingFormalAttribute[source]¶
Bases:
ProvExceptionException for a relation missing a party it requires.
hadMember,alternateOf,specializationOfandmentionOfrefuse a record that lacks an entity or a collection.mentionOfmay omit its bundle.
- class prov.model.ProvValueError[source]¶
Bases:
ProvException,ValueErrorA value a
Literalor 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
Literalis built with a language tag that is empty or not shaped like a BCP 47 tag. A subclass of bothProvExceptionandValueError, so a caller can catch either.
- class prov.model.ProvUnificationError[source]¶
Bases:
ProvExceptionRaised 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).