Prerequisites
- Python 3.8 or higher
- A wallet with 0G tokens for paying storage fees (get testnet tokens)
- An EVM-compatible private key for signing Flow contract transactions
Install the SDK
Install the published package from PyPI:Dependencies
The SDK installs the following automatically:pycryptodome— Keccak256 hashing for merkle treesweb3— blockchain RPC and contract interactioneth-account— transaction signingrequests— HTTP client for indexer and storage nodes
Verify the install
The package name on PyPI is0g-storage-sdk, but because that name isn’t a valid Python identifier, the SDK ships its top-level modules as core, utils, contracts, and models. Confirm the install by importing a core module:
Import paths
Storage SDK imports use the top-levelcore and utils modules:
Network endpoints
The Storage SDK needs two endpoints:- Blockchain RPC — for Flow contract submissions (shared with the Compute SDK)
- Indexer RPC — for storage node discovery and file location queries
- Testnet
- Mainnet
| Network | Chain ID | Blockchain RPC | Indexer RPC |
|---|---|---|---|
| Mainnet | 16661 | https://evmrpc.0g.ai | https://indexer-storage-turbo.0g.ai |
| Testnet (Galileo) | 16602 | https://evmrpc-testnet.0g.ai | https://indexer-storage-testnet-turbo.0g.ai |
Configure credentials
Keep your private key out of source control. Set it as an environment variable or read it from a.env file:
python-dotenv is not a direct dependency of the Storage SDK, so install it separately if you want .env support: pip install python-dotenv.
Quick sanity check
Compute a merkle root from a byte string — no network calls, no wallet required:0x… root hash, your install works.
Connect to an indexer
Initialize theIndexer client and confirm connectivity by listing sharded nodes:
trusted count confirms the indexer is reachable and the network is healthy.
Get testnet tokens
Storage submissions cost a small on-chain fee. For testnet:Request tokens
Visit faucet.0g.ai and paste your address.
Confirm the balance
Check the Galileo block explorer.
Troubleshooting
ModuleNotFoundError: No module named 'core'
ModuleNotFoundError: No module named 'core'
Make sure you installed
0g-storage-sdk (not 0g_py_storage directly from git) and that your virtual environment is active. The package exposes top-level modules; if you see a namespace collision with another core module in your project, install into a fresh venv.Failed to connect to indexer
Failed to connect to indexer
Verify the indexer URL is reachable:If you’re behind a corporate proxy, set
HTTPS_PROXY before running the script.Merkle root mismatch with TypeScript SDK
Merkle root mismatch with TypeScript SDK
The Python and TypeScript SDKs produce byte-exact identical root hashes. A mismatch usually means different input bytes (trailing newlines, encoding differences) or different chunk sizes. Both SDKs default to 256-byte chunks and 256 KB segments — don’t override these unless you know you need to.
Upload hangs or times out
Upload hangs or times out
Uploads can take 3–5 minutes for files to propagate across shards. The SDK retries transient failures automatically. If it times out entirely, check that your
BLOCKCHAIN_RPC and INDEXER_RPC both resolve and your wallet has enough balance to pay the storage fee.Next steps
Upload & download files
End-to-end walkthrough of the upload and download flow.
Merkle trees & proofs
Generate and validate cryptographic proofs for file integrity.
KV storage
Read and write key-value streams with access control.
Large files
Splitable uploads and fragment downloads for multi-GB files.