hippius 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hippius-0.1.0/PKG-INFO +475 -0
- hippius-0.1.0/README.md +445 -0
- hippius-0.1.0/hippius_sdk/__init__.py +11 -0
- hippius-0.1.0/hippius_sdk/cli.py +658 -0
- hippius-0.1.0/hippius_sdk/client.py +246 -0
- hippius-0.1.0/hippius_sdk/ipfs.py +985 -0
- hippius-0.1.0/hippius_sdk/substrate.py +688 -0
- hippius-0.1.0/pyproject.toml +47 -0
hippius-0.1.0/PKG-INFO
ADDED
@@ -0,0 +1,475 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: hippius
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Python SDK and CLI for Hippius blockchain storage
|
5
|
+
Home-page: https://github.com/thenervelab/hippius-sdk
|
6
|
+
Author: Dubs
|
7
|
+
Author-email: dubs@dubs.rs
|
8
|
+
Requires-Python: >=3.8,<4.0
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
10
|
+
Classifier: Intended Audience :: Developers
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
17
|
+
Provides-Extra: clipboard
|
18
|
+
Requires-Dist: base58 (>=2.1.1,<3.0.0)
|
19
|
+
Requires-Dist: ipfshttpclient (>=0.7.0,<0.8.0)
|
20
|
+
Requires-Dist: pydantic (>=2.0.0,<3.0.0)
|
21
|
+
Requires-Dist: pynacl (>=1.5.0,<2.0.0)
|
22
|
+
Requires-Dist: pyperclip (>=1.8.2,<2.0.0) ; extra == "clipboard"
|
23
|
+
Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
|
24
|
+
Requires-Dist: requests (>=2.28.1,<3.0.0)
|
25
|
+
Requires-Dist: substrate-interface (>=1.4.2,<2.0.0)
|
26
|
+
Project-URL: Documentation, https://github.com/thenervelab/hippius-sdk/docs
|
27
|
+
Project-URL: Repository, https://github.com/thenervelab/hippius-sdk
|
28
|
+
Description-Content-Type: text/markdown
|
29
|
+
|
30
|
+
# Hippius
|
31
|
+
|
32
|
+
A Python SDK and CLI for interacting with Hippius blockchain storage, designed specifically for ML developers working with Bittensor.
|
33
|
+
|
34
|
+
## Features
|
35
|
+
|
36
|
+
- IPFS operations: Upload and download files to/from IPFS
|
37
|
+
- Multiple connection methods for IPFS (RPC or HTTP API)
|
38
|
+
- Human-readable formatting of file sizes and CIDs
|
39
|
+
- Simple and intuitive API for ML developers
|
40
|
+
- Substrate blockchain integration for decentralized storage references
|
41
|
+
- End-to-end encryption for secure file storage and retrieval
|
42
|
+
- Built-in CLI tools for encryption key generation
|
43
|
+
|
44
|
+
## Installation
|
45
|
+
|
46
|
+
```bash
|
47
|
+
# Using pip
|
48
|
+
pip install hippius
|
49
|
+
|
50
|
+
# Using Poetry
|
51
|
+
poetry add hippius
|
52
|
+
|
53
|
+
# With clipboard support for encryption key utility
|
54
|
+
poetry add hippius -E clipboard
|
55
|
+
```
|
56
|
+
|
57
|
+
## Quick Start
|
58
|
+
|
59
|
+
```python
|
60
|
+
from hippius_sdk import HippiusClient
|
61
|
+
|
62
|
+
# Initialize the client with default connections to Hippius network
|
63
|
+
client = HippiusClient()
|
64
|
+
|
65
|
+
# Or specify custom endpoints
|
66
|
+
client = HippiusClient(
|
67
|
+
ipfs_gateway="https://ipfs.io", # For downloads (default)
|
68
|
+
ipfs_api_url="http://relay-fr.hippius.network:5001", # For uploads (default)
|
69
|
+
)
|
70
|
+
|
71
|
+
# Upload a file to IPFS
|
72
|
+
result = client.upload_file("path/to/your/model.pt")
|
73
|
+
print(f"File uploaded with CID: {result['cid']}")
|
74
|
+
print(f"File size: {result['size_formatted']}")
|
75
|
+
|
76
|
+
# Download a file from IPFS
|
77
|
+
dl_result = client.download_file(result['cid'], "path/to/save/model.pt")
|
78
|
+
print(f"Download successful in {dl_result['elapsed_seconds']} seconds")
|
79
|
+
print(f"File size: {dl_result['size_formatted']}")
|
80
|
+
|
81
|
+
# Check if a file exists
|
82
|
+
exists_result = client.exists(result['cid'])
|
83
|
+
print(f"File exists: {exists_result['exists']}")
|
84
|
+
print(f"Gateway URL: {exists_result['gateway_url']}")
|
85
|
+
|
86
|
+
# Get file content directly
|
87
|
+
content_result = client.cat(result['cid'])
|
88
|
+
if content_result['is_text']:
|
89
|
+
print(f"Content preview: {content_result['text_preview']}")
|
90
|
+
else:
|
91
|
+
print(f"Binary content (hex): {content_result['hex_preview']}")
|
92
|
+
print(f"Content size: {content_result['size_formatted']}")
|
93
|
+
|
94
|
+
# Pin a file to ensure it stays on the network
|
95
|
+
pin_result = client.pin(result['cid'])
|
96
|
+
print(f"Pinning successful: {pin_result['success']}")
|
97
|
+
print(f"Message: {pin_result['message']}")
|
98
|
+
|
99
|
+
# Format a CID for display
|
100
|
+
formatted_cid = client.format_cid(result['cid'])
|
101
|
+
print(f"Formatted CID: {formatted_cid}")
|
102
|
+
|
103
|
+
# Format file size for display
|
104
|
+
formatted_size = client.format_size(1024 * 1024)
|
105
|
+
print(f"Formatted size: {formatted_size}") # Output: 1.00 MB
|
106
|
+
```
|
107
|
+
|
108
|
+
## Encryption Support
|
109
|
+
|
110
|
+
Hippius SDK supports end-to-end encryption for secure file storage and retrieval using the NaCl (libsodium) cryptography library.
|
111
|
+
|
112
|
+
### Generating an Encryption Key
|
113
|
+
|
114
|
+
```bash
|
115
|
+
# After installing the SDK, you can use the built-in command-line tool:
|
116
|
+
hippius-keygen
|
117
|
+
|
118
|
+
# Generate and copy to clipboard (requires pyperclip)
|
119
|
+
hippius-keygen --copy
|
120
|
+
```
|
121
|
+
|
122
|
+
### Setting Up Encryption
|
123
|
+
|
124
|
+
The SDK can be configured to use encryption in several ways:
|
125
|
+
|
126
|
+
1. Through environment variables (recommended for development):
|
127
|
+
```
|
128
|
+
# In your .env file
|
129
|
+
HIPPIUS_ENCRYPTION_KEY=your-base64-encoded-key
|
130
|
+
HIPPIUS_ENCRYPT_BY_DEFAULT=true
|
131
|
+
```
|
132
|
+
|
133
|
+
2. Directly in code:
|
134
|
+
```python
|
135
|
+
import base64
|
136
|
+
from hippius_sdk import HippiusClient
|
137
|
+
|
138
|
+
# Decode the base64 key
|
139
|
+
encryption_key = base64.b64decode("your-base64-encoded-key")
|
140
|
+
|
141
|
+
# Initialize client with encryption enabled
|
142
|
+
client = HippiusClient(
|
143
|
+
encrypt_by_default=True,
|
144
|
+
encryption_key=encryption_key
|
145
|
+
)
|
146
|
+
|
147
|
+
# Or generate a new key programmatically
|
148
|
+
encoded_key = client.generate_encryption_key()
|
149
|
+
print(f"Generated key: {encoded_key}")
|
150
|
+
```
|
151
|
+
|
152
|
+
### Using Encryption
|
153
|
+
|
154
|
+
Once configured, encryption works transparently:
|
155
|
+
|
156
|
+
```python
|
157
|
+
# Upload with encryption (uses default setting)
|
158
|
+
result = client.upload_file("sensitive_data.txt")
|
159
|
+
|
160
|
+
# Explicitly enable/disable encryption for a specific operation
|
161
|
+
encrypted_result = client.upload_file("sensitive_data.txt", encrypt=True)
|
162
|
+
unencrypted_result = client.upload_file("public_data.txt", encrypt=False)
|
163
|
+
|
164
|
+
# Download and decrypt automatically
|
165
|
+
dl_result = client.download_file(encrypted_result['cid'], "decrypted_file.txt")
|
166
|
+
|
167
|
+
# Explicitly control decryption
|
168
|
+
decrypted_result = client.download_file(encrypted_result['cid'], "output.txt", decrypt=True)
|
169
|
+
raw_result = client.download_file(encrypted_result['cid'], "still_encrypted.txt", decrypt=False)
|
170
|
+
|
171
|
+
# View encrypted content
|
172
|
+
content = client.cat(encrypted_result['cid'], decrypt=True)
|
173
|
+
```
|
174
|
+
|
175
|
+
## Command Line Interface
|
176
|
+
|
177
|
+
The Hippius SDK includes a powerful command-line interface (CLI) that provides access to all major features of the SDK directly from your terminal.
|
178
|
+
|
179
|
+
### Basic Usage
|
180
|
+
|
181
|
+
```bash
|
182
|
+
# Get help and list available commands
|
183
|
+
hippius --help
|
184
|
+
|
185
|
+
# Set global options
|
186
|
+
hippius --gateway https://ipfs.io --api-url https://relay-fr.hippius.network --verbose
|
187
|
+
```
|
188
|
+
|
189
|
+
### IPFS Operations
|
190
|
+
|
191
|
+
```bash
|
192
|
+
# Download a file from IPFS
|
193
|
+
hippius download QmCID123 output_file.txt
|
194
|
+
|
195
|
+
# Check if a CID exists
|
196
|
+
hippius exists QmCID123
|
197
|
+
|
198
|
+
# Display file content
|
199
|
+
hippius cat QmCID123
|
200
|
+
|
201
|
+
# Store a file on IPFS and Hippius Marketplace
|
202
|
+
hippius store my_file.txt
|
203
|
+
|
204
|
+
# Store a directory on IPFS and Hippius Marketplace
|
205
|
+
hippius store-dir ./my_directory
|
206
|
+
```
|
207
|
+
|
208
|
+
### Account Operations
|
209
|
+
|
210
|
+
```bash
|
211
|
+
# Check available credits for an account
|
212
|
+
hippius credits
|
213
|
+
|
214
|
+
# Check credits for a specific account
|
215
|
+
hippius credits 5H1QBRF7T7dgKwzVGCgS4wioudvMRf9K4NEDzfuKLnuyBNzH
|
216
|
+
|
217
|
+
# View files stored by an account
|
218
|
+
hippius files
|
219
|
+
|
220
|
+
# View files for a specific account
|
221
|
+
hippius files 5H1QBRF7T7dgKwzVGCgS4wioudvMRf9K4NEDzfuKLnuyBNzH
|
222
|
+
|
223
|
+
# Show all miners for each file
|
224
|
+
hippius files --all-miners
|
225
|
+
```
|
226
|
+
|
227
|
+
### Encryption
|
228
|
+
|
229
|
+
```bash
|
230
|
+
# Generate an encryption key
|
231
|
+
hippius keygen
|
232
|
+
|
233
|
+
# Generate and copy to clipboard
|
234
|
+
hippius keygen --copy
|
235
|
+
|
236
|
+
# Upload with encryption
|
237
|
+
hippius store my_file.txt --encrypt
|
238
|
+
|
239
|
+
# Download and decrypt
|
240
|
+
hippius download QmCID123 output_file.txt --decrypt
|
241
|
+
```
|
242
|
+
|
243
|
+
### Using Environment Variables
|
244
|
+
|
245
|
+
The CLI automatically reads from your `.env` file for common settings:
|
246
|
+
|
247
|
+
```
|
248
|
+
IPFS_GATEWAY=https://ipfs.io
|
249
|
+
IPFS_API_URL=https://relay-fr.hippius.network
|
250
|
+
SUBSTRATE_URL=wss://rpc.hippius.network
|
251
|
+
SUBSTRATE_SEED_PHRASE="your twelve word seed phrase..."
|
252
|
+
SUBSTRATE_DEFAULT_MINERS=miner1,miner2,miner3
|
253
|
+
HIPPIUS_ENCRYPTION_KEY=your-base64-encoded-key
|
254
|
+
HIPPIUS_ENCRYPT_BY_DEFAULT=true|false
|
255
|
+
```
|
256
|
+
|
257
|
+
## Detailed Usage
|
258
|
+
|
259
|
+
### IPFS Operations
|
260
|
+
|
261
|
+
```python
|
262
|
+
from hippius_sdk import IPFSClient
|
263
|
+
|
264
|
+
# Initialize the IPFS client (uses Hippius relay node by default)
|
265
|
+
ipfs_client = IPFSClient()
|
266
|
+
|
267
|
+
# Or specify custom endpoints
|
268
|
+
ipfs_client = IPFSClient(
|
269
|
+
gateway="https://ipfs.io", # For downloads
|
270
|
+
api_url="http://relay-fr.hippius.network:5001" # For uploads
|
271
|
+
)
|
272
|
+
|
273
|
+
# Upload a file
|
274
|
+
result = ipfs_client.upload_file("path/to/your/file.txt")
|
275
|
+
cid = result["cid"]
|
276
|
+
size = result["size_formatted"]
|
277
|
+
|
278
|
+
# Upload a directory
|
279
|
+
dir_result = ipfs_client.upload_directory("path/to/your/directory")
|
280
|
+
dir_cid = dir_result["cid"]
|
281
|
+
file_count = dir_result["file_count"]
|
282
|
+
total_size = dir_result["size_formatted"]
|
283
|
+
|
284
|
+
# Download a file
|
285
|
+
dl_result = ipfs_client.download_file(cid, "path/to/save/file.txt")
|
286
|
+
success = dl_result["success"]
|
287
|
+
elapsed_time = dl_result["elapsed_seconds"]
|
288
|
+
|
289
|
+
# Check if a CID exists
|
290
|
+
exists_result = ipfs_client.exists(cid)
|
291
|
+
exists = exists_result["exists"]
|
292
|
+
gateway_url = exists_result["gateway_url"]
|
293
|
+
|
294
|
+
# Get file content directly
|
295
|
+
content_result = ipfs_client.cat(cid)
|
296
|
+
content = content_result["content"]
|
297
|
+
is_text = content_result["is_text"]
|
298
|
+
preview = content_result["text_preview"] if is_text else content_result["hex_preview"]
|
299
|
+
|
300
|
+
# Pin a file
|
301
|
+
pin_result = ipfs_client.pin(cid)
|
302
|
+
success = pin_result["success"]
|
303
|
+
message = pin_result["message"]
|
304
|
+
|
305
|
+
# Format a CID
|
306
|
+
formatted_cid = ipfs_client.format_cid("6261666b7265696134...") # Hex-encoded CID
|
307
|
+
# Will return a proper formatted CID like "bafkrei..."
|
308
|
+
|
309
|
+
# Format a file size
|
310
|
+
human_readable = ipfs_client.format_size(1048576) # 1 MB
|
311
|
+
```
|
312
|
+
|
313
|
+
### IPFS Connection Methods
|
314
|
+
|
315
|
+
The SDK provides robust connection handling for IPFS:
|
316
|
+
|
317
|
+
1. **RPC Connection (Default)**: Attempts to connect to the IPFS node via its RPC port (typically 5001) using the `ipfshttpclient` library.
|
318
|
+
|
319
|
+
2. **HTTP API Fallback**: If the RPC connection fails, the SDK automatically falls back to using the HTTP REST API (same approach as used in web browsers).
|
320
|
+
|
321
|
+
This dual approach ensures maximum compatibility across different environments. The fallback happens automatically, so you don't need to worry about it.
|
322
|
+
|
323
|
+
## Development
|
324
|
+
|
325
|
+
```bash
|
326
|
+
# Clone the repository
|
327
|
+
git clone https://github.com/your-username/hippius-sdk.git
|
328
|
+
cd hippius-sdk
|
329
|
+
|
330
|
+
# Install dependencies
|
331
|
+
poetry install
|
332
|
+
|
333
|
+
# With encryption and clipboard support
|
334
|
+
poetry install -E clipboard
|
335
|
+
|
336
|
+
# Run tests
|
337
|
+
poetry run pytest
|
338
|
+
```
|
339
|
+
|
340
|
+
## Testing Locally
|
341
|
+
|
342
|
+
You can test Hippius locally during development or before publishing to PyPI. Here's how to test both the SDK and CLI components:
|
343
|
+
|
344
|
+
### 1. Install in Development Mode
|
345
|
+
|
346
|
+
The easiest way to test everything together is to install the package in development mode:
|
347
|
+
|
348
|
+
```bash
|
349
|
+
# In the root directory of the project
|
350
|
+
poetry install
|
351
|
+
|
352
|
+
# With encryption and clipboard support
|
353
|
+
poetry install -E clipboard
|
354
|
+
```
|
355
|
+
|
356
|
+
This makes both the SDK and CLI available while still allowing you to make changes to the code.
|
357
|
+
|
358
|
+
### 2. Testing the CLI
|
359
|
+
|
360
|
+
After installing in development mode, you can run the CLI commands directly:
|
361
|
+
|
362
|
+
```bash
|
363
|
+
# Basic commands
|
364
|
+
hippius --help
|
365
|
+
hippius download QmCID123 output_file.txt
|
366
|
+
hippius keygen
|
367
|
+
|
368
|
+
# To see what commands would do without actually running them, add --verbose
|
369
|
+
hippius --verbose store myfile.txt
|
370
|
+
```
|
371
|
+
|
372
|
+
If you want to test CLI changes without reinstalling the package:
|
373
|
+
|
374
|
+
```bash
|
375
|
+
# Run the CLI module directly
|
376
|
+
python -m hippius_sdk.cli download QmCID123 output_file.txt
|
377
|
+
|
378
|
+
# Or make it executable and run it directly
|
379
|
+
chmod +x hippius_sdk/cli.py
|
380
|
+
./hippius_sdk/cli.py download QmCID123 output_file.txt
|
381
|
+
```
|
382
|
+
|
383
|
+
### 3. Testing the SDK
|
384
|
+
|
385
|
+
To test the SDK components, you can create a small test script:
|
386
|
+
|
387
|
+
```python
|
388
|
+
# test_script.py
|
389
|
+
from hippius_sdk import HippiusClient
|
390
|
+
from dotenv import load_dotenv
|
391
|
+
import os
|
392
|
+
|
393
|
+
# Load environment variables
|
394
|
+
load_dotenv()
|
395
|
+
|
396
|
+
# Create a client
|
397
|
+
client = HippiusClient()
|
398
|
+
|
399
|
+
# Test a simple operation
|
400
|
+
print("Testing IPFS client...")
|
401
|
+
try:
|
402
|
+
result = client.exists("QmZ4tDuvesekSs4qM5ZBKpXiZGun7S2CYtEZRB3DYXkjGx")
|
403
|
+
print(f"Result: {result}")
|
404
|
+
except Exception as e:
|
405
|
+
print(f"Error: {e}")
|
406
|
+
```
|
407
|
+
|
408
|
+
Then run it:
|
409
|
+
|
410
|
+
```bash
|
411
|
+
python test_script.py
|
412
|
+
```
|
413
|
+
|
414
|
+
### 4. Running Unit Tests
|
415
|
+
|
416
|
+
You can use pytest to run the test suite:
|
417
|
+
|
418
|
+
```bash
|
419
|
+
# Run all tests
|
420
|
+
poetry run pytest
|
421
|
+
|
422
|
+
# Run specific tests
|
423
|
+
poetry run pytest tests/test_ipfs.py
|
424
|
+
|
425
|
+
# Run a specific test function
|
426
|
+
poetry run pytest tests/test_ipfs.py::test_upload_file
|
427
|
+
```
|
428
|
+
|
429
|
+
### 5. Building and Testing the Package
|
430
|
+
|
431
|
+
If you want to test the exact package that will be uploaded to PyPI:
|
432
|
+
|
433
|
+
```bash
|
434
|
+
# Build the package
|
435
|
+
poetry build
|
436
|
+
|
437
|
+
# Install the built package in a virtual environment
|
438
|
+
python -m venv test_env
|
439
|
+
source test_env/bin/activate # On Windows: test_env\Scripts\activate
|
440
|
+
pip install dist/hippius-0.1.0-py3-none-any.whl
|
441
|
+
|
442
|
+
# Test the installed package
|
443
|
+
hippius --help
|
444
|
+
```
|
445
|
+
|
446
|
+
### Troubleshooting Local Testing
|
447
|
+
|
448
|
+
1. **IPFS Connection Issues**: Make sure you have either:
|
449
|
+
- A local IPFS daemon running (`ipfs daemon` in a separate terminal)
|
450
|
+
- Or proper environment variables set in `.env` for remote connections
|
451
|
+
|
452
|
+
2. **Missing Dependencies**: If you get import errors, ensure all dependencies are installed:
|
453
|
+
```bash
|
454
|
+
poetry install --all-extras
|
455
|
+
```
|
456
|
+
|
457
|
+
3. **CLI Not Found**: If the `hippius` command isn't found after installing, try:
|
458
|
+
```bash
|
459
|
+
# Verify it's installed
|
460
|
+
poetry show hippius
|
461
|
+
|
462
|
+
# Check your PATH
|
463
|
+
which hippius
|
464
|
+
```
|
465
|
+
|
466
|
+
4. **Substrate Issues**: For marketplace operations, make sure your `.env` has the correct `SUBSTRATE_SEED_PHRASE` and `SUBSTRATE_URL` values.
|
467
|
+
|
468
|
+
## Contributing
|
469
|
+
|
470
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
471
|
+
|
472
|
+
## License
|
473
|
+
|
474
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
475
|
+
|