Skip to main content

A Python package that provides IPFSDict and IPFSDictChain objects, which are dictionary-like data structures that store their state on IPFS and keep track of changes.

Project description

ipfs_dict_chain

ipfs_dict_chain is a Python package that provides IPFSDict and IPFSDictChain objects, which are dictionary-like data structures that store their state on IPFS and keep track of changes, basically creating a mini-blockchain of dicts on IPFS for efficient and secure data management.

Requirements

  • Python >= 3.10
  • An IPFS node
  • aioipfs >= 0.6.3
  • multiaddr >= 0.0.9

Installation

To install the ipfs_dict_chain package, run the following command:

pip install ipfs-dict-chain

Usage

By default, ipfs_dict_chain will attempt to connect to an IPFS node running on localhost (127.0.0.1) on port 5001. If your IPFS node is running with these default settings, you can start using the package immediately.

If your IPFS node is running on a different host or port, you must first connect to it using the connect() function:

from ipfs_dict_chain.IPFS import connect

# Connect to a local IPFS node on a different port
connect(host='127.0.0.1', port=8080)

# Or connect to a remote IPFS node
connect(host='192.168.1.100', port=5001)

The connect() function will test the connection by attempting to add a small test object to IPFS. If the connection fails, it will raise an IPFSError with details about the connection failure.

IPFSDict

IPFSDict is a dictionary-like object that stores its data on IPFS. Here's an example of how to use IPFSDict:

from ipfs_dict_chain.IPFSDict import IPFSDict

my_dict = IPFSDict()

# Add data to the dictionary, you can use both dot notation and bracket notation
my_dict.my_key1 = 'value1'
my_dict['my_key2'] = 'value2'

# Save the dictionary to IPFS
cid = my_dict.save()

# Load the dictionary from IPFS
loaded_dict = IPFSDict(cid=cid)

# Access the data
print(loaded_dict.my_key1)  # Output: 'value1'

IPFSDictChain

IPFSDictChain is a dictionary-like data structure that stores its state on IPFS and keeps track of changes. Here's an example of how to use IPFSDictChain:

from ipfs_dict_chain.IPFSDictChain import IPFSDictChain

my_chain = IPFSDictChain()

# Add data to the dictionary, you can use both dot notation and bracket notation
my_chain.my_key1 = 'value1'
my_chain['my_key2'] = 'value2'

# Save the current state of the dictionary to IPFS
cid1 = my_chain.save()

my_chain.my_key1 = 'value1_changed'
cid2 = my_chain.save()

# Load the dictionary from IPFS
loaded_chain = IPFSDictChain(cid=cid2)

# Access the data
print(loaded_chain.my_key1)  # Output: 'value1_changed'

# Get the changes between the current state and the previous state
changes = loaded_chain.changes()
print(changes)  # Output: {'previous_cid': {'old': None, 'new': 'QmSdydVMD2E7taf42gwQNhakBAc379u8y9X4Kbyoig36Fs'}, 'my_key1': {'old': 'value1', 'new': 'value1_changed'}}

# Get the previous states of the dictionary
previous_states = loaded_chain.get_previous_states()
print(previous_states)  # Output: [{'previous_cid': None, 'my_key1': 'value1', 'my_key2': 'value2'}]

# Get the previous CIDs of the dictionary
previous_cids = loaded_chain.get_previous_cids()
print(previous_cids)  # Output: ['QmSdydVMD2E7taf42gwQNhakBAc379u8y9X4Kbyoig36Fs']

Documentation

The documentation is built using Sphinx and can be found at GitHub Pages.

To build the documentation locally:

  1. Install the documentation dependencies:

    pip install sphinx sphinx-rtd-theme
    
  2. Build the documentation:

    cd docs
    python -m sphinx.cmd.build -b html source build/html
    

The documentation will be available in docs/build/html/index.html.

Contributing

If you'd like to contribute to the ipfs_dict_chain package, please submit a pull request, issue, or feature request on the project's GitHub repository.

License

This package is released under the MIT License.

Authors

  • Wouter Glorieux - Twitter
  • Serendipity - AI Assistant

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipfs_dict_chain-1.0.8.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ipfs_dict_chain-1.0.8-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file ipfs_dict_chain-1.0.8.tar.gz.

File metadata

  • Download URL: ipfs_dict_chain-1.0.8.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for ipfs_dict_chain-1.0.8.tar.gz
Algorithm Hash digest
SHA256 9cdd5d672ae35c17aead7af5b6e3143d897aefb08face22e0d3014e7602ccb68
MD5 d360ff5753e5bf57131b7fa340cf6217
BLAKE2b-256 bea7dc6bcbd51b1f750c56332ae56ce38bb602a44aedd8394df05e31b52aa220

See more details on using hashes here.

File details

Details for the file ipfs_dict_chain-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for ipfs_dict_chain-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0f1388b5fae731bf4155ef566261dd8d2aabd348be31a0a9e7f3f244b8ab3b4b
MD5 b64a58927ca5c73d993f7b15b288406f
BLAKE2b-256 e2624854d5d03b3899875befb8f71d517aa277b72ee0243cb551248ad0a8e3ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page