prov.serializers package

Module contents

class prov.serializers.Serializer(document=None)[source]

Bases: object

Serializer for PROV documents.

deserialize(stream, **kwargs)[source]

Abstract method for deserializing.

Parameters

stream – Stream object to deserialize the document from.

document = None

PROV document to serialise.

serialize(stream, **kwargs)[source]

Abstract method for serializing.

Parameters

stream – Stream object to serialize the document into.

prov.serializers.get(format_name)[source]

Returns the serializer class for the specified format. Raises a DoNotExist

prov.serializers.provjson module

class prov.serializers.provjson.ProvJSONDecoder(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)[source]

Bases: json.decoder.JSONDecoder

decode(s, *args, **kwargs)[source]

Return the Python representation of s (a str instance containing a JSON document).

class prov.serializers.provjson.ProvJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: json.encoder.JSONEncoder

default(o)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
exception prov.serializers.provjson.ProvJSONException[source]

Bases: prov.Error

class prov.serializers.provjson.ProvJSONSerializer(document=None)[source]

Bases: prov.serializers.Serializer

PROV-JSON serializer for ProvDocument

deserialize(stream, **kwargs)[source]

Deserialize from the PROV JSON representation to a ProvDocument instance.

Parameters

stream – Input data.

serialize(stream, **kwargs)[source]

Serializes a ProvDocument instance to PROV-JSON.

Parameters

stream – Where to save the output.

prov.serializers.provn module

class prov.serializers.provn.ProvNSerializer(document=None)[source]

Bases: prov.serializers.Serializer

PROV-N serializer for ProvDocument

deserialize(stream, **kwargs)[source]

Abstract method for deserializing.

Parameters

stream – Stream object to deserialize the document from.

serialize(stream, **kwargs)[source]

Serializes a prov.model.ProvDocument instance to a PROV-N.

Parameters

stream – Where to save the output.

prov.serializers.provrdf module

PROV-RDF serializers for ProvDocument

exception prov.serializers.provrdf.ProvRDFException[source]

Bases: prov.Error

class prov.serializers.provrdf.ProvRDFSerializer(document=None)[source]

Bases: prov.serializers.Serializer

PROV-O serializer for ProvDocument

deserialize(stream, rdf_format='trig', relation_mapper={rdflib.term.URIRef('http://www.w3.org/ns/prov#actedOnBehalfOf'): 'delegation', rdflib.term.URIRef('http://www.w3.org/ns/prov#alternateOf'): 'alternate', rdflib.term.URIRef('http://www.w3.org/ns/prov#hadMember'): 'membership', rdflib.term.URIRef('http://www.w3.org/ns/prov#mentionOf'): 'mention', rdflib.term.URIRef('http://www.w3.org/ns/prov#specializationOf'): 'specialization', rdflib.term.URIRef('http://www.w3.org/ns/prov#used'): 'usage', rdflib.term.URIRef('http://www.w3.org/ns/prov#wasAssociatedWith'): 'association', rdflib.term.URIRef('http://www.w3.org/ns/prov#wasAttributedTo'): 'attribution', rdflib.term.URIRef('http://www.w3.org/ns/prov#wasDerivedFrom'): 'derivation', rdflib.term.URIRef('http://www.w3.org/ns/prov#wasEndedBy'): 'end', rdflib.term.URIRef('http://www.w3.org/ns/prov#wasGeneratedBy'): 'generation', rdflib.term.URIRef('http://www.w3.org/ns/prov#wasInfluencedBy'): 'influence', rdflib.term.URIRef('http://www.w3.org/ns/prov#wasInformedBy'): 'communication', rdflib.term.URIRef('http://www.w3.org/ns/prov#wasInvalidatedBy'): 'invalidation', rdflib.term.URIRef('http://www.w3.org/ns/prov#wasStartedBy'): 'start'}, predicate_mapper={rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'): <QualifiedName: prov:label>, rdflib.term.URIRef('http://www.w3.org/ns/prov#atLocation'): <QualifiedName: prov:location>, rdflib.term.URIRef('http://www.w3.org/ns/prov#atTime'): <QualifiedName: prov:time>, rdflib.term.URIRef('http://www.w3.org/ns/prov#endedAtTime'): <QualifiedName: prov:endTime>, rdflib.term.URIRef('http://www.w3.org/ns/prov#hadActivity'): <QualifiedName: prov:activity>, rdflib.term.URIRef('http://www.w3.org/ns/prov#hadGeneration'): <QualifiedName: prov:generation>, rdflib.term.URIRef('http://www.w3.org/ns/prov#hadPlan'): <QualifiedName: prov:plan>, rdflib.term.URIRef('http://www.w3.org/ns/prov#hadRole'): <QualifiedName: prov:role>, rdflib.term.URIRef('http://www.w3.org/ns/prov#hadUsage'): <QualifiedName: prov:usage>, rdflib.term.URIRef('http://www.w3.org/ns/prov#startedAtTime'): <QualifiedName: prov:startTime>}, **kwargs)[source]

Deserialize from the PROV-O representation to a ProvDocument instance.

Parameters
  • stream – Input data.

  • rdf_format – The RDF format of the input data, default: TRiG.

serialize(stream=None, rdf_format='trig', PROV_N_MAP={<QualifiedName: prov:Entity>: 'entity', <QualifiedName: prov:Activity>: 'activity', <QualifiedName: prov:Generation>: 'wasGeneratedBy', <QualifiedName: prov:Usage>: 'used', <QualifiedName: prov:Communication>: 'wasInformedBy', <QualifiedName: prov:Start>: 'wasStartedBy', <QualifiedName: prov:End>: 'wasEndedBy', <QualifiedName: prov:Invalidation>: 'wasInvalidatedBy', <QualifiedName: prov:Derivation>: 'wasDerivedFrom', <QualifiedName: prov:Agent>: 'agent', <QualifiedName: prov:Attribution>: 'wasAttributedTo', <QualifiedName: prov:Association>: 'wasAssociatedWith', <QualifiedName: prov:Delegation>: 'actedOnBehalfOf', <QualifiedName: prov:Influence>: 'wasInfluencedBy', <QualifiedName: prov:Alternate>: 'alternateOf', <QualifiedName: prov:Specialization>: 'specializationOf', <QualifiedName: prov:Mention>: 'mentionOf', <QualifiedName: prov:Membership>: 'hadMember', <QualifiedName: prov:Bundle>: 'bundle'}, **kwargs)[source]

Serializes a ProvDocument instance to PROV-O.

Parameters
  • stream – Where to save the output.

  • rdf_format – The RDF format of the output, default to TRiG.

prov.serializers.provrdf.walk(children, level=0, path=None, usename=True)[source]

Generate all the full paths in a tree, as a dict.

Example

>>> from prov.serializers.provrdf import walk
>>> iterables = [('a', lambda: [1, 2]), ('b', lambda: [3, 4])]
>>> [val['a'] for val in walk(iterables)]
[1, 1, 2, 2]
>>> [val['b'] for val in walk(iterables)]
[3, 4, 3, 4]

prov.serializers.provxml module

exception prov.serializers.provxml.ProvXMLException[source]

Bases: prov.Error

class prov.serializers.provxml.ProvXMLSerializer(document=None)[source]

Bases: prov.serializers.Serializer

PROV-XML serializer for ProvDocument

deserialize(stream, **kwargs)[source]

Deserialize from PROV-XML representation to a ProvDocument instance.

Parameters

stream – Input data.

deserialize_subtree(xml_doc, bundle)[source]

Deserialize an etree element containing a PROV document or a bundle and write it to the provided internal object.

Parameters
  • xml_doc – An etree element containing the information to read.

  • bundle – The bundle object to write to.

serialize(stream, force_types=False, **kwargs)[source]

Serializes a ProvDocument instance to PROV-XML.

Parameters
  • stream – Where to save the output.

  • force_types (boolean, optional) – Will force xsd:types to be written for most attributes mainly PROV-“attributes”, e.g. tags not in the PROV namespace. Off by default meaning xsd:type attributes will only be set for prov:type, prov:location, and prov:value as is done in the official PROV-XML specification. Furthermore the types will always be set if the Python type requires it. False is a good default and it should rarely require changing.

serialize_bundle(bundle, element=None, force_types=False)[source]

Serializes a bundle or document to PROV XML.

Parameters
  • bundle – The bundle or document.

  • element – The XML element to write to. Will be created if None.

  • force_types (boolean, optional) – Will force xsd:types to be written for most attributes mainly PROV-“attributes”, e.g. tags not in the PROV namespace. Off by default meaning xsd:type attributes will only be set for prov:type, prov:location, and prov:value as is done in the official PROV-XML specification. Furthermore the types will always be set if the Python type requires it. False is a good default and it should rarely require changing.