Python client and CLI for the OnchFS (On-Chain File System) protocol on Tezos blockchain
Project description
OnchFS Python Client
Python client for the OnchFS (On-Chain File System) protocol on Tezos blockchain.
Installation
pip install pyonchfs
Command Line Interface
OnchFS includes a powerful CLI for easy file uploads and downloads:
Setup
# Set your Tezos secret key (required for uploads)
export TZ_SK="edsk3oYfrKXpqHgXTWXm7YKzGAKszVQ7ehh9PViFdJc83pV7VDiJnB"
Upload Files
# Upload a single file
onchfs upload myfile.txt
# or
python -m onchfs upload myfile.txt
# Upload a directory with compression
onchfs upload ./my-website --compress
# Upload to mainnet (defaults to ghostnet)
onchfs upload ./docs --network mainnet
# Skip confirmation prompt
onchfs upload ./data --yes
Download Files
# Download from hash
onchfs download 6a89c4e7d38f8ffc1ddba97037aa83181b56326bf5e1f5b95070ba7789813832 ./downloaded
# or
python -m onchfs download 6a89c4e7d38f8ffc1ddba97037aa83181b56326bf5e1f5b95070ba7789813832 ./downloaded
# Download from onchfs:// URL
onchfs download onchfs://6a89c4e7d38f8ffc1ddba97037aa83181b56326bf5e1f5b95070ba7789813832 ./downloaded
CLI Options
onchfs --help # Show help
python -m onchfs --help # Alternative way
onchfs upload --help # Upload help
onchfs download --help # Download help
# Global options
--network {mainnet,ghostnet,localnet} # Choose network (default: ghostnet)
# Upload options
--compress # Enable compression
--chunk-size SIZE # Set chunk size in bytes (default: 16384)
--yes, -y # Skip confirmation prompt
Python API
Quick Start
Download Files
from onchfs import OnchfsClient, Network
client = OnchfsClient(network=Network.MAINNET)
# Download directory
directory_hash = "f8020273fba472a3e87baf6eb0f3929915edabace0fa409a261c4c4fa6684b21"
files = client.download_directory(directory_hash, "downloaded/")
# Get specific file
content = client.get_file(directory_hash, "index.html")
Prepare Files for Upload
from onchfs import OnchfsClient, IFile, OnchfsPrepareOptions
client = OnchfsClient()
# Prepare files
files = [
IFile(path="hello.txt", content=b"Hello, OnchFS!"),
IFile(path="data.json", content=b'{"message": "test"}')
]
directory_inode = client.prepare_files(files)
directory_hash = client.get_directory_hash(directory_inode)
Upload a Whole Directory (Improved API)
import os
from onchfs import OnchfsUploader, Network, OnchfsPrepareOptions
from pytezos import pytezos
# Load Tezos secret key from environment
secret_key = os.getenv('TZ_SK')
if not secret_key:
raise ValueError("TZ_SK environment variable not set")
# Initialize PyTezos client with secret key
pytezos_client = pytezos.using(
key=secret_key,
shell=Network.GHOSTNET.value # or your preferred RPC endpoint
)
# Initialize OnchFS uploader with network (contracts auto-resolved!)
uploader = OnchfsUploader(pytezos_client, Network.GHOSTNET)
# Prepare directory for upload
directory_path = "./my_website" # Path to your directory
directory_inode = uploader.prepare_directory(
directory_path,
options=OnchfsPrepareOptions(compress=True)
)
# Get the directory hash (this is what you'll use to access files)
directory_hash = uploader.get_directory_hash(directory_inode)
print(f"Directory hash: {directory_hash}")
# Estimate upload cost
cost_estimate = uploader.estimate_cost(directory_inode)
print(f"Estimated cost: {cost_estimate}")
# Upload to OnchFS (contract address automatically resolved!)
print("Starting upload...")
result = uploader.upload_directory(directory_inode)
print(f"Upload operation hash: {result.operation_hash}")
print(f"Your files are now accessible at: onchfs://{result.directory_hash}")
Environment Setup:
# Set your Tezos secret key
export TZ_SK="edsk..." # Your Tezos secret key
# Run your upload script
python upload_directory.py
API
OnchfsUploader (Recommended)
from onchfs import OnchfsUploader, Network
from pytezos import pytezos
# Initialize with automatic contract resolution
uploader = OnchfsUploader(pytezos_client, Network.GHOSTNET)
# Upload without specifying contract address
result = uploader.upload_directory(directory_inode)
OnchfsClient
client = OnchfsClient(
network=Network.MAINNET, # MAINNET, GHOSTNET, LOCALNET
contract_address=None, # Optional custom contract
pytezos_client=None # Optional PyTezos client
)
Download Methods:
download_directory(hash, target_dir)- Download all filesget_file(hash, filename)- Get file contentget_file_metadata(hash, filename)- Get file metadatalist_directory(hash)- List directory contents
Preparation Methods:
prepare_files(files, options=None)- Prepare files for uploadprepare_directory(path, options=None)- Prepare directoryestimate_upload_cost(directory_inode)- Estimate costsget_directory_hash(directory_inode)- Get hash
Types
from onchfs import IFile, OnchfsPrepareOptions
file = IFile(path="example.txt", content=b"content")
options = OnchfsPrepareOptions(chunk_size=16384, compress=True)
Examples
Run the included examples:
python examples/download_example.py
python examples/prepare_example.py
Contract Addresses
- Mainnet:
KT1Ae7dT1gsLw2tRnUMXSCmEyF74KVkM6LUo - Ghostnet:
KT1FA8AGGcJha6S6MqfBUiibwTaYhK8u7s9Q
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyonchfs-0.1.3.tar.gz.
File metadata
- Download URL: pyonchfs-0.1.3.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d019a9ef2202f173fc89a516716402e424a700ae850425bc825bf456074dc1f2
|
|
| MD5 |
694154a4af9068c47c654f3687bd06bd
|
|
| BLAKE2b-256 |
b6952f228d150e72334a296566a98edce7b5a66926200749ee14a701bff6cff2
|
Provenance
The following attestation bundles were made for pyonchfs-0.1.3.tar.gz:
Publisher:
workflow.yml on objkt-com/pyonchfs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyonchfs-0.1.3.tar.gz -
Subject digest:
d019a9ef2202f173fc89a516716402e424a700ae850425bc825bf456074dc1f2 - Sigstore transparency entry: 527371662
- Sigstore integration time:
-
Permalink:
objkt-com/pyonchfs@7f6aa2a3dfbf5a1a5bcd82cbac1798aeaed7397d -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/objkt-com
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@7f6aa2a3dfbf5a1a5bcd82cbac1798aeaed7397d -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyonchfs-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pyonchfs-0.1.3-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c96a68e82c8fb5e00a5c365367525f14b617f614e0a800ba82242e24ecdc615
|
|
| MD5 |
6e03dac96a3469c6ae53017a3a02a8e2
|
|
| BLAKE2b-256 |
eb6b6d136af6f07b8f836bbe72ebb85622a2cd0fa2d60b916f42b1111088f20e
|
Provenance
The following attestation bundles were made for pyonchfs-0.1.3-py3-none-any.whl:
Publisher:
workflow.yml on objkt-com/pyonchfs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyonchfs-0.1.3-py3-none-any.whl -
Subject digest:
7c96a68e82c8fb5e00a5c365367525f14b617f614e0a800ba82242e24ecdc615 - Sigstore transparency entry: 527371691
- Sigstore integration time:
-
Permalink:
objkt-com/pyonchfs@7f6aa2a3dfbf5a1a5bcd82cbac1798aeaed7397d -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/objkt-com
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@7f6aa2a3dfbf5a1a5bcd82cbac1798aeaed7397d -
Trigger Event:
push
-
Statement type: