Skip to main content

Ceramic Python client

This Ceramic client implements the payload building, encoding, and signing needed to interact with the Ceramic Network. It currently supports ModelInstanceDocument.

Features

  • Implements payload building, encoding, and signing for Ceramic interactions
  • Currently supports ModelInstanceDocument

Working with Ceramic streams

Install the Ceramic client using pip

pip3 install ceramic_python

Create a stream

First, generate a Decentralized Identifier (DID) using a DID library.

from ceramic_python.helper import get_iso_timestamp
from ceramic_python.did import DID
from ceramic_python.ceramic_client import CeramicClient
from ceramic_python.model_instance_document import ModelInstanceDocument, ModelInstanceDocumentMetadataArgs

def initialize_ceramic():
    did = DID(
        id="did:key:z6MkefHJkv4f658zsR59uRAZqCa8wuz8hKJ8VGQUHznN3XB9",
        private_key="e40070a71c32a1b22dbd2123cde261446a9e9d2dfefefef03ec4619697d14eb2",
    )
    ceramic_client = CeramicClient("<CERAMIC_NODE_URL>", did)
    return ceramic_client, did

def create_document():
    ceramic_client, did = initialize_ceramic()

    metadata_args = ModelInstanceDocumentMetadataArgs(
        controller=did.id,
        model="kjzl6hvfrbw6c7wjdc58s11ru9y3h2ubzq6yixqy134xkc63bnnzjcnwaimf711",
    )

    content = {
        "title": "Alice",
        "createdAt": get_iso_timestamp(),
        "updatedAt": get_iso_timestamp(),
    }

    doc = ModelInstanceDocument.create(ceramic_client, content, metadata_args)
    print(f"Stream created with ID: {doc.stream_id}")
    return doc

# Create a new stream
create_document()

Read stream

from ceramic_python.did import DID
from ceramic_python.ceramic_client import CeramicClient
from ceramic_python.model_instance_document import ModelInstanceDocument

def initialize_ceramic():
    did = DID(
        id="did:key:z6MkefHJkv4f658zsR59uRAZqCa8wuz8hKJ8VGQUHznN3XB9",
        private_key="e40070a71c32a1b22dbd2123cde261446a9e9d2dfefefef03ec4619697d14eb2",
    )
    ceramic_client = CeramicClient("<CERAMIC_NODE_URL>", did)
    return ceramic_client, did

def load_document(stream_id):
    ceramic_client, _ = initialize_ceramic()
    doc = ModelInstanceDocument.load(ceramic_client, stream_id)
    print(f"Data from stream: {doc.content}")
    return doc

# Load data from a specific stream
load_document(<STREAM_ID>)

Update stream (Replace)

from ceramic_python.helper import get_iso_timestamp
from ceramic_python.did import DID
from ceramic_python.ceramic_client import CeramicClient
from ceramic_python.model_instance_document import ModelInstanceDocument

def initialize_ceramic():
    did = DID(
        id="did:key:z6MkefHJkv4f658zsR59uRAZqCa8wuz8hKJ8VGQUHznN3XB9",
        private_key="e40070a71c32a1b22dbd2123cde261446a9e9d2dfefefef03ec4619697d14eb2",
    )
    ceramic_client = CeramicClient("<CERAMIC_NODE_URL>", did)
    return ceramic_client, did

def update_document(stream_id):
    ceramic_client, _ = initialize_ceramic()
    doc = ModelInstanceDocument.load(ceramic_client, stream_id)

    updated_content = {
        "title": "Second",
        "createdAt": get_iso_timestamp(),
        "updatedAt": get_iso_timestamp(),
    }

    updated = doc.replace(updated_content)
    print(f"Updated data: {updated.content}")
    return updated

# Update an existing stream
update_document(<STREAM_ID>)

Update stream (Patch)

from ceramic_python.helper import get_iso_timestamp
from ceramic_python.did import DID
from ceramic_python.ceramic_client import CeramicClient
from ceramic_python.model_instance_document import ModelInstanceDocument

def initialize_ceramic():
    did = DID(
        id="did:key:z6MkefHJkv4f658zsR59uRAZqCa8wuz8hKJ8VGQUHznN3XB9",
        private_key="e40070a71c32a1b22dbd2123cde261446a9e9d2dfefefef03ec4619697d14eb2",
    )
    ceramic_client = CeramicClient("<CERAMIC_NODE_URL>", did)
    return ceramic_client, did

def patch_document(stream_id):
    ceramic_client, _ = initialize_ceramic()
    doc = ModelInstanceDocument.load(ceramic_client, stream_id)

    patch = [
        {"op": "replace", "path": "/title", "value": "Patched Title"},
        {"op": "replace", "path": "/updatedAt", "value": get_iso_timestamp()}
    ]

    patched_doc = doc.patch(patch)
    print(f"Stream patched. New content: {patched_doc.content}")
    return patched_doc

# Patch an existing stream
patch_document(<STREAM_ID>)

For Developement

  • Clone this repository
git clone git@github.com:indexnetwork/ceramic-python.git
cd ceramic-client
  • Install Pipenv.
  • Generate the virtual environment:
make new_env && pipenv shell

Credits

This project is largely based on the work done by the team at https://github.com/valory-xyz/ceramic-py/. We are grateful for their contributions to the Ceramic ecosystem and the open-source community.

Metadata

Release files for ceramic-python 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ceramic-python 0.1.7
File Size Uploaded Provenance
ceramic_python-0.1.7.tar.gz 9.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ceramic-python 0.1.7
File Interpreter ABI Platform
ceramic_python-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / ceramic_python-0.1.7.tar.gz

Download URL ceramic_python-0.1.7.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
05e3997d3ead3f1a3ceb57415ae91ab9e4d7e7836e1acdad61c2c63a3ebfe754
BLAKE2b-256 checksum
How to use checksums
24ff5a47e6a9980f14c53914dc6b424fcbc7e13261f3cf400f758f2cd9518fcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.15

Release files / ceramic_python-0.1.7-py3-none-any.whl

Download URL ceramic_python-0.1.7-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c1bc52ed49b3bb4b95db997d56540de25ca3b73217784dd50de45dc64f04470
BLAKE2b-256 checksum
How to use checksums
88a16ed063c80224e37debea78bf60bdeedf25882c74f55b03f0e4de789df8e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.15

Security for ceramic-python 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page