{"id":5009,"library":"prov","title":"PROV Python Library","description":"The `prov` library is a Python implementation of the W3C Provenance Data Model (PROV). It facilitates the creation, manipulation, and serialization/deserialization of provenance documents, supporting formats like PROV-JSON, PROV-XML, and PROV-O (RDF). The library is actively maintained, with its latest version being 2.1.1, and releases occur as needed to support newer Python versions and fix bugs.","status":"active","version":"2.1.1","language":"en","source_language":"en","source_url":"https://github.com/trungdong/prov","tags":["provenance","W3C","PROV","PROV-DM","PROV-JSON","PROV-XML","PROV-O","RDF","graph","model"],"install":[{"cmd":"pip install prov","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for PROV-O (RDF) serialization/deserialization. Version must be less than 7 for compatibility with prov 2.x.","package":"rdflib","optional":true},{"reason":"Required for graphical visualization of PROV documents (generates DOT files for Graphviz).","package":"pydot","optional":true}],"imports":[{"note":"Core classes like ProvDocument and Namespace reside in the 'prov.model' submodule.","wrong":"from prov import ProvDocument","symbol":"ProvDocument","correct":"from prov.model import ProvDocument"},{"note":"Core classes like ProvDocument and Namespace reside in the 'prov.model' submodule.","wrong":"from prov import Namespace","symbol":"Namespace","correct":"from prov.model import Namespace"},{"note":"Constants are defined in the 'prov.constants' submodule.","symbol":"PROV_REC_NAMESPACE","correct":"from prov.constants import PROV_REC_NAMESPACE"}],"quickstart":{"code":"import datetime\nfrom prov.model import ProvDocument, Namespace, PROV_REC_NAMESPACE\n\n# Create a new provenance document\ndoc = ProvDocument()\n\n# Declare namespaces\ndoc.add_namespace('ex', 'http://example.org/')\ndoc.set_default_namespace('http://example.com/prov-example/')\n\n# Declare entities, activities, agents\ne1 = doc.entity('ex:entity1', {'prov:label': 'Example Entity 1'})\na1 = doc.activity('ex:activity1', datetime.datetime.now(), datetime.datetime.now(), {'prov:label': 'Example Activity 1'})\nag1 = doc.agent('ex:agent1', {'prov:label': 'Example Agent 1', PROV_REC_NAMESPACE['type']: PROV_REC_NAMESPACE['Person']})\n\n# Establish relationships\ndoc.wasGeneratedBy(e1, a1, datetime.datetime.now())\ndoc.wasAssociatedWith(a1, ag1)\n\n# Print the PROV-N representation\nprint(doc.get_provn())\n\n# To serialize to PROV-JSON (requires the 'json' extra, installed with `pip install prov[json]`)\n# from prov.serializers import provjson\n# import json\n# with open('example.json', 'w') as f:\n#     provjson.ProvJSONSerializer(doc).serialize(f)\n","lang":"python","description":"This example demonstrates how to create a simple PROV document, define namespaces, add entities, activities, and agents, and link them with provenance relations. It then prints the PROV-N (PROV Notation) representation of the document. For JSON or XML serialization, additional dependencies and specific serializers are used."},"warnings":[{"fix":"Upgrade to Python 3.9+ and `prov` version 2.x. Ensure your code is compatible with Python 3.","message":"Python 2.x support was removed in version 2.0.0. The library is now Python 3 only.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Ensure your project runs on Python 3.9 or newer. The latest `prov` version (2.1.1) supports Python 3.9-3.13.","message":"Support for several End-of-Life Python versions has been dropped incrementally. Python 3.3 was removed in v1.5.3, Python 3.6 and 3.7 in v2.0.1, and Python 3.8 in v2.0.2. Current versions require Python >=3.9.","severity":"breaking","affected_versions":"All versions up to 2.1.1"},{"fix":"When installing `prov[rdf]`, ensure `rdflib` is installed as `rdflib<7` or check for newer `prov` versions that explicitly support `rdflib` 7+ if available.","message":"The `rdflib` dependency, used for PROV-O (RDF) serialization, was restricted to versions less than 7 (`rdflib <7`) starting from `prov` version 2.0.1 due to compatibility issues.","severity":"breaking","affected_versions":">=2.0.1"},{"fix":"If you were using `pydotplus` with older `prov` versions, switch to `pydot` for graphical visualizations with newer `prov` releases. Ensure `Graphviz` is also installed.","message":"The `pydotplus` dependency for graphical output was replaced by `pydot` in version 1.5.1.","severity":"deprecated","affected_versions":">=1.5.1"},{"fix":"Review the changelog for `prov` version 1.0.0 and 1.0.1. Significant code changes may be required for migration from pre-1.0 versions.","message":"The underlying data model for PROV documents underwent a rewrite in version 1.0.0, introducing incompatibilities with pre-1.0 versions. Methods like `add_record()` were renamed to `new_record()` in v1.0.1, and references to PROV elements became `QualifiedName` instances.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Rename your local file or module to something other than `prov.py` to avoid masking the actual library.","message":"Naming a local Python file or module `prov.py` will cause an `ImportError` due to a name collision with the `prov` library itself.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}