Created
April 29, 2025 08:18
-
-
Save autonome/c039b65f0a97e546f1682de0c389755e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from hippius_sdk import HippiusClient | |
# Initialize the client with default connections to Hippius network | |
client = HippiusClient() | |
# Or specify custom endpoints | |
client = HippiusClient( | |
ipfs_gateway="https://ipfs.io", # For downloads (default) | |
ipfs_api_url="https://store.hippius.network", # For uploads (default) | |
) | |
async def main(): | |
# Upload a file to IPFS | |
result = await client.upload_file("prg.jpg") | |
print(f"File uploaded with CID: {result['cid']}") | |
print(f"File size: {result['size_formatted']}") | |
# Download a file from IPFS | |
dl_result = await client.download_file(result['cid'], "prg-downloaded.jpg") | |
print(f"Download successful in {dl_result['elapsed_seconds']} seconds") | |
print(f"File size: {dl_result['size_formatted']}") | |
# Check if a file exists | |
exists_result = await client.exists(result['cid']) | |
print(f"File exists: {exists_result['exists']}") | |
print(f"Gateway URL: {exists_result['gateway_url']}") | |
# Get file content directly | |
content_result = await client.cat(result['cid']) | |
if content_result['is_text']: | |
print(f"Content preview: {content_result['text_preview']}") | |
else: | |
print(f"Binary content (hex): {content_result['hex_preview']}") | |
print(f"Content size: {content_result['size_formatted']}") | |
# Pin a file to ensure it stays on the network | |
pin_result = await client.pin(result['cid']) | |
print(f"Pinning successful: {pin_result['success']}") | |
print(f"Message: {pin_result['message']}") | |
# Format a CID for display | |
formatted_cid = client.format_cid(result['cid']) | |
print(f"Formatted CID: {formatted_cid}") | |
# Format file size for display | |
formatted_size = client.format_size(1024 * 1024) | |
print(f"Formatted size: {formatted_size}") # Output: 1.00 MB | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment