0G Storage Python SDK
This repository provides a Python SDK for interacting with 0G Storage.
Installation
- Requires Python 3.9+
- Install (editable):
pip install -e . - Dev deps:
pip install -e .[test]
Quick Start (Upload: Indexer or Node)
import os
from zg_storage import EvmClient
from zg_storage.indexer import IndexerClient
from zg_storage.transfer import NodeUploader, NodeUploaderConfig, UploadOption
USE_INDEXER = True
private_key = os.environ["PRIVATE_KEY"]
evm = EvmClient(
rpc_url="https://evmrpc-testnet.0g.ai",
private_key=private_key,
)
if USE_INDEXER:
indexer = IndexerClient(
"https://indexer-storage-testnet-turbo.0g.ai",
evm_client=evm,
flow_address="0x...",
)
tx_hash, root_hex = indexer.upload(file_path="your_file.dat", tags=b"", option=UploadOption())
else:
cfg = NodeUploaderConfig(
nodes=["http://node-1:5678", "http://node-2:5678"],
evm_client=evm,
flow_address="0x...",
)
uploader = NodeUploader.from_config(cfg)
tx_hash, root_hex = uploader.upload(file_path="your_file.dat", tags=b"", option=UploadOption())
print("tx:", tx_hash)
print("root:", root_hex)
Download (Indexer or Node List)
from zg_storage.indexer import IndexerClient
from zg_storage.transfer import DownloadOption, NodeDownloader, NodeDownloaderConfig
USE_INDEXER = True
root = "0x..."
target = "downloaded.bin"
opt = DownloadOption()
if USE_INDEXER:
indexer = IndexerClient("https://indexer-storage-testnet-turbo.0g.ai")
indexer.download(root=root, filename=target, option=opt)
else:
cfg = NodeDownloaderConfig(
nodes=["http://node-1:5678", "http://node-2:5678"],
)
downloader = NodeDownloader.from_config(cfg)
downloader.download(root=root, target=target, option=opt)
For all detailed parameters, advanced options, and latest endpoint/config guidance, see https://doc.0g.ai.
KV Write (Memory Upload)
import os
from zg_storage import EvmClient
from zg_storage.indexer import IndexerClient
from zg_storage.kv import StreamDataBuilder
from zg_storage.kv.types import create_tags
from zg_storage.core.data import BytesDataSource
from zg_storage.transfer import UploadOption
private_key = os.environ["PRIVATE_KEY"]
evm = EvmClient(rpc_url="https://evmrpc-testnet.0g.ai", private_key=private_key)
indexer = IndexerClient(
"https://indexer-storage-testnet-turbo.0g.ai",
evm_client=evm,
flow_address="0x...",
)
builder = StreamDataBuilder()
builder.set(
stream_id="0x" + "00" * 32, # dummy stream id
key=b"demo_key", # dummy key
data=b"demo_value", # dummy value
)
stream_data = builder.build(sorted_items=True)
payload = stream_data.encode()
tags = create_tags(builder.stream_ids(), sorted_ids=True)
opt = UploadOption(tags=tags)
tx_hash, root_hex = indexer.upload(
file_path=BytesDataSource(payload),
tags=tags,
option=opt,
)
KV Read
from zg_storage.kv import KvClient
kv = KvClient("http://your-kv-node:6789")
data = kv.get_values(
"0x" + "00" * 32, # dummy stream id
["demo_key"], # dummy keys
)
print(data)
Development
- Requires Python 3.9+
- Install dev deps:
pip install -e .[test] - Run tests:
pytest
Metadata
Release files for zg-storage 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zg_storage-0.2.0.tar.gz | 142.3 kB | Without provenance | Details for zg_storage-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zg_storage-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for zg_storage-0.2.0-py3-none-any.whl |
Total release size: 289.1 kB
Release files / zg_storage-0.2.0.tar.gz
| Download URL | zg_storage-0.2.0.tar.gz |
|---|---|
| Size | 142.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb25223ffbbfb476961f056494023f6f9f01d9e3d8d7437816281967cff9553e
|
|
BLAKE2b-256 checksum How to use checksums |
73614efa5f52a3ad58e4da53b36945a0e2be28f249ae93b2e9b0c8a6b79bc22d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Release files / zg_storage-0.2.0-py3-none-any.whl
| Download URL | zg_storage-0.2.0-py3-none-any.whl |
|---|---|
| Size | 146.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ba4e58525a2b3361b79ef061a9adbce76a0492153f6763287546244304b42a5d
|
|
BLAKE2b-256 checksum How to use checksums |
eaeb765f6a4f7843d65d6ab222a1928b8eaa69a9734be01a6922f8eb9d963754
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Security for zg-storage 0.2.0
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.