Welcome to PROV 2 BigchainDB’s documentation!¶
PROV 2 BigchainDB¶
Introduction¶
This python module provides three different clients to store W3C-PROV documents into a federation of BigchainDB nodes. All clients are implemented with respect to the proposed concepts from the masters thesis Trustworthy Provenance Recording using a blockchain-like database.
See full documentation at: prov2bigchaindb.readthedocs.io
Software Requirements¶
- Python 3.5 or Python 3.6
- Python development libraries
- GCC and Make
- A local rethinkdb server
Installation¶
PyPi¶
Install it by running:
pip install prov2bigchaindb
You can view prov2bigchaindb on PyPi’s package index
Source¶
# Clone project
git clone git@github.com:DLR-SC/prov2bigchaindb.git
cd prov2bigchaindb
# Setup virtual environment
python -m venv env
source env/bin/activate
# Install dependencies and package into virtual enviroment
make setup
Usage¶
DocumentConceptClient¶
from prov2bigchaindb.tests.core import setup_test_files
from prov2bigchaindb.core import utils, clients
test_prov_files = setup_test_files()
prov_document = utils.to_prov_document(content=test_prov_files["simple2"])
doc_client = clients.DocumentConceptClient(account_id="ID", host="127.0.0.1", port=9984)
# Store a document
tx_id = doc_client.save_document(prov_document)
# Retrieve a document
doc = doc_client.get_document(tx_id)
GraphConceptClient¶
from prov2bigchaindb.tests.core import setup_test_files
from prov2bigchaindb.core import utils, clients
test_prov_files = setup_test_files()
prov_document = utils.to_prov_document(content=test_prov_files["simple2"])
graph_client = clients.GraphConceptClient(host="127.0.0.1", port=9984)
# Store a document
tx_ids = graph_client.save_document(prov_document)
# Retrieve a document
doc = graph_client.get_document(tx_ids)
RoleConceptClient¶
from prov2bigchaindb.tests.core import setup_test_files
from prov2bigchaindb.core import utils, clients
test_prov_files = setup_test_files()
prov_document = utils.to_prov_document(content=test_prov_files["simple2"])
role_client = clients.RoleConceptClient(host="127.0.0.1", port=9984)
# Store a document
tx_ids = role_client.save_document(prov_document)
# Retrieve a document
doc = role_client.get_document(tx_ids)
Development¶
Contribute¶
Please, fork the code on Github and develop your feature in a new branch split from the develop branch. Commit your code to the main project by sending a pull request onto the develop branch
- Issue Tracker: https://github.com/DLR-SC/prov2bigchaindb/issues
- Source Code: https://github.com/DLR-SC/prov2bigchaindb
Setup¶
# Clone project
git clone git@github.com:DLR-SC/prov2bigchaindb.git
cd prov2bigchaindb
# Setup virtual environment
python -m venv env
source env/bin/activate
# Install dependencies
make dev-setup
Execute tests¶
make test
Coverage report¶
make coverage
Compile documentation¶
make docs
Changelog¶
Version 0.4.1 (2018-04-09)¶
- Updated BigchainDB to 1.3.0
- Updated db-driver to 0.4.1
- Updated networkx to 2.1
- Updated prov to 1.5.2
Version 0.4.0 (2017-06-29)¶
- Updated bigchaindb components to 1.0.0rc1
Version 0.3.1 (2017-04-07)¶
- Added travis-ci support
- Updated documentation
Version 0.3.0 (2017-04-01)¶
- Support for the role-based concept
Version 0.2.0 (2017-03-05)¶
- Support for the graph-based concept
- Added unit tests
Version 0.1.0 (2017-02-21)¶
- Support for the document-based concept
- Added basic unit tests
- Intergation of Gitlab-CI
Testing Howto¶
To run the test local follow the next steps
1. Setup your env¶
# Clone project
git clone git@github.com:DLR-SC/prov2bigchaindb.git
cd prov2bigchaindb
# Setup virtual environment
python -m venv env
source env/bin/activate
# Install dependencies
make dev-setup
2. Start your BigchainDB test node¶
The tests require a running BigchainDB and RethinkDB instance.
make run
3. Setup environment variables¶
- BDB_HOST: Default: 127.0.0.1
- BDB_PORT: Default: 9984
If you like to connect to BigchainDB node, hosted on a different port and/or machine:
BDB_HOST=127.0.0.1
BDB_HOST=9984
4. Run your tests¶
# Change to env
source env/bin/activate
#Start tests
make test
prov2bigchaindb¶
prov2bigchaindb package¶
Subpackages¶
prov2bigchaindb.core package¶
Submodules¶
prov2bigchaindb.core.accounts module¶
-
class
prov2bigchaindb.core.accounts.
BaseAccount
(account_id: str, store: prov2bigchaindb.core.local_stores.SqliteStore)[source]¶ Bases:
object
BigchainDB Base Account
-
class
prov2bigchaindb.core.accounts.
DocumentConceptAccount
(account_id: str, store: prov2bigchaindb.core.local_stores.SqliteStore)[source]¶ Bases:
prov2bigchaindb.core.accounts.BaseAccount
BigchainDB Document Concept Account
-
class
prov2bigchaindb.core.accounts.
GraphConceptAccount
(prov_element: prov.model.ProvElement, prov_relations: dict, id_mapping: dict, namespaces: list, store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]¶ Bases:
prov2bigchaindb.core.accounts.BaseAccount
BigchainDB Graph Concept Account
-
get_tx_id
() → str[source]¶ Get the tx_id that describes the account in BigchainDB
Returns: Transaction id of account Return type: str
-
has_relations_with_id
() → bool[source]¶ Indicates whether an account has relation with ids or not :return: True if one or more relation does have ids :rtype: bool
-
has_relations_without_id
() → bool[source]¶ Indicates whether an account has relation without ids or not :return: True if one or more relation does have ids :rtype: bool
-
save_relations_with_ids
(bdb_connection: bigchaindb_driver.driver.BigchainDB) → list[source]¶ Writes all assets with relations (having ids) to BigchainDB
Parameters: bdb_connection (BigchainDB) – Connection object for BigchainDB Returns: Transactions ids of all relations Return type: list
-
-
class
prov2bigchaindb.core.accounts.
RoleConceptAccount
(agent: prov.model.ProvAgent, relations: list, elements: dict, id_mapping: dict, namespaces: list, store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]¶ Bases:
prov2bigchaindb.core.accounts.BaseAccount
BigchainDB Graph Concept Account
-
get_tx_id
() → str[source]¶ Get the tx_id that describes the account in BigchainDB
Returns: Transaction id of account Return type: str
-
prov2bigchaindb.core.clients module¶
-
class
prov2bigchaindb.core.clients.
BaseClient
(host: str = '0.0.0.0', port: int = 9984, num_connections: int = 5, local_store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]¶ Bases:
object
BigchainDB Base Client
-
test_transaction
(tx: dict) → bool[source]¶ Validate a transaction against BigchainDB
Parameters: tx (dict) – Transaction to test Returns: True or Exception Return type: bool
-
-
class
prov2bigchaindb.core.clients.
DocumentConceptClient
(account_id: str = None, host: str = '0.0.0.0', port: int = 9984, num_connections: int = 1, local_store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]¶
-
class
prov2bigchaindb.core.clients.
GraphConceptClient
(host: str = '0.0.0.0', port: int = 9984, num_connections: int = 5, local_store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]¶ Bases:
prov2bigchaindb.core.clients.BaseClient
-
static
calculate_account_data
(prov_document: prov.model.ProvDocument) → list[source]¶ Transforms a ProvDocument into a tuple with ProvElement, list of ProvRelation and list of Namespaces
Parameters: prov_document – Document to transform Returns: List of tuples(element, relations, namespace) Return type: list
-
static
-
class
prov2bigchaindb.core.clients.
RoleConceptClient
(host: str = '0.0.0.0', port: int = 9984, num_connections: int = 5, local_store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]¶ Bases:
prov2bigchaindb.core.clients.BaseClient
-
static
calculate_account_data
(prov_document: prov.model.ProvDocument) → list[source]¶ Transforms a ProvDocument into a list of tuples including: ProvAgent, list of ProvRelations from agent, list of ProvElements associated to ProvAgent, list of Namespaces
Parameters: prov_document – Document to transform Returns: List of tuples(ProvAgent, list(), list(), list()) Return type: list
-
static
prov2bigchaindb.core.exceptions module¶
-
exception
prov2bigchaindb.core.exceptions.
CreateRecordException
[source]¶ Bases:
prov2bigchaindb.core.exceptions.Prov2BigchainDBException
-
exception
prov2bigchaindb.core.exceptions.
ParseException
[source]¶ Bases:
prov2bigchaindb.core.exceptions.Prov2BigchainDBException
-
exception
prov2bigchaindb.core.exceptions.
NoAccountFoundException
[source]¶ Bases:
prov2bigchaindb.core.exceptions.Prov2BigchainDBException
-
exception
prov2bigchaindb.core.exceptions.
AccountNotCreatedException
[source]¶ Bases:
prov2bigchaindb.core.exceptions.Prov2BigchainDBException
-
exception
prov2bigchaindb.core.exceptions.
NoRelationFoundException
[source]¶ Bases:
prov2bigchaindb.core.exceptions.Prov2BigchainDBException
-
exception
prov2bigchaindb.core.exceptions.
TransactionIdNotFound
[source]¶ Bases:
prov2bigchaindb.core.exceptions.Prov2BigchainDBException
-
exception
prov2bigchaindb.core.exceptions.
BlockIdNotFound
[source]¶ Bases:
prov2bigchaindb.core.exceptions.Prov2BigchainDBException
prov2bigchaindb.core.local_stores module¶
-
class
prov2bigchaindb.core.local_stores.
BaseStore
(db_name: str = None)[source]¶ Bases:
object
-
write_account
(account_id: str, public_key: str, private_key: str, tx_id: str = None)[source]¶ Writes a new account entry in to the table accounts
Parameters:
-
-
class
prov2bigchaindb.core.local_stores.
SqliteStore
(db_name: str = ':memory:')[source]¶ Bases:
prov2bigchaindb.core.local_stores.BaseStore
-
write_account
(account_id: str, public_key: str, private_key: str, tx_id: str = None)[source]¶ Writes a new account entry in to the table accounts
Parameters:
-
prov2bigchaindb.core.utils module¶
-
prov2bigchaindb.core.utils.
to_prov_document
(content: str) → prov.model.ProvDocument[source]¶ Takes a string, bytes or ProvDocument as argument and return a ProvDocument The strings or bytes can contain JSON or XML representations of PROV
Parameters: content – String or BufferedReader or ProvDocument Returns: ProvDocument Return type: ProvDocument
-
prov2bigchaindb.core.utils.
wait_until_valid
(tx_id: str, bdb_connection: bigchaindb_driver.driver.BigchainDB)[source]¶ Waits until a transaction is valid in BigchainDB
Parameters: - tx_id (str) – Id of transaction to wait on
- bdb_connection (BigchainDB) – Connection object for BigchainDB
-
prov2bigchaindb.core.utils.
is_valid_tx
(tx_id: str, bdb_connection: bigchaindb_driver.driver.BigchainDB) → bool[source]¶ Checks once if a transaction is valid
Parameters: - tx_id (str) – Id of transaction to check
- bdb_connection (BigchainDB) – Connection object for BigchainDB
Returns: True if valid
Return type:
-
prov2bigchaindb.core.utils.
is_block_to_tx_valid
(tx_id: str, bdb_connection: bigchaindb_driver.driver.BigchainDB) → bool[source]¶ Checks if block with transaction is valid
Parameters: - tx_id (str) – Id of transaction which should be included in the
- bdb_connection (BigchainDB) – Connection object for BigchainDB
Returns: True if transactions is in block and block is valid
Return type: