Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
ec0ecef
conversion of all high level structs and functions for CreateBucket
itsgurmannatsohal Feb 2, 2025
620e607
test-write-access
d4v1d03 Feb 4, 2025
0af1095
writeaccesstest
d4v1d03 Feb 4, 2025
0a58304
added view, delete bucket
d4v1d03 Feb 5, 2025
3096cac
linking structs
itsgurmannatsohal Feb 5, 2025
5c2d525
added encryption
d4v1d03 Feb 6, 2025
ea44583
Merge branch 'CreateBucket' of github.com:itsgurmannatsohal/akavesdk-…
d4v1d03 Feb 6, 2025
4e4b408
adding protobuf files
itsgurmannatsohal Feb 10, 2025
4cf4921
added memory.py
d4v1d03 Feb 15, 2025
f77861f
adding tests and code testing
itsgurmannatsohal Feb 15, 2025
e43a8fc
testing and subsequent corrections
itsgurmannatsohal Feb 15, 2025
c05f30d
finished with sdk.py and fixed some import errors
tejas-2512 Feb 20, 2025
d0ffc3b
sdk_ipc needs some fixing, done with erasure code(reed-solomon)
tejas-2512 Feb 23, 2025
9f48637
Merge pull request #2 from itsgurmannatsohal/CreateBucket
Abhay-2811 Feb 28, 2025
d9c30e4
erasure code added
d4v1d03 Mar 5, 2025
0e316f8
added build-dag func and fixed imports
d4v1d03 Mar 8, 2025
d87356b
fixes in connection.py
d4v1d03 Mar 13, 2025
85ba051
added erasure code tests
d4v1d03 Mar 17, 2025
b20af29
working tests
d4v1d03 Mar 17, 2025
4406b14
reedsolomon reverted and working tests for erasure code
d4v1d03 Mar 17, 2025
da58185
Merge pull request #11 from d4v1d03/dev
Abhay-2811 Mar 18, 2025
5fd1602
added sdk with working tests
d4v1d03 Apr 1, 2025
2820a02
added list emptybuckets/bucketserror tests
d4v1d03 Apr 1, 2025
11c705a
Merge pull request #21 from d4v1d03/dev
Abhay-2811 Apr 1, 2025
fc75965
added dag.py with working tests
d4v1d03 Apr 1, 2025
fc1f5ec
fixes
d4v1d03 Apr 1, 2025
d94a852
Merge pull request #22 from d4v1d03/dev
Abhay-2811 Apr 2, 2025
84651f2
added ipc sdk with working tests
d4v1d03 Apr 5, 2025
9213932
added streatimg sdk
d4v1d03 Apr 5, 2025
c4c5a63
Merge pull request #23 from d4v1d03/dev
Abhay-2811 Apr 6, 2025
4cab1ff
packaging the sdk
d4v1d03 Apr 9, 2025
677a9ad
Merge branch 'akave-ai:dev' into dev
d4v1d03 Apr 9, 2025
5db6df5
fixed dependency version issue
d4v1d03 Apr 9, 2025
a5e56ca
package working
d4v1d03 Apr 10, 2025
107c6dd
Merge pull request #27 from d4v1d03/dev
Abhay-2811 Apr 10, 2025
90a30aa
working package
d4v1d03 Apr 10, 2025
854f7c3
Merge branch 'akave-ai:dev' into dev
d4v1d03 Apr 13, 2025
3aadff1
fixes in readme
d4v1d03 Apr 14, 2025
a39aaa1
fixed sdk streaming with working tests
d4v1d03 Apr 16, 2025
a585e4f
ipc fixing
d4v1d03 Apr 23, 2025
f0a013e
ipc fixes again
d4v1d03 Apr 24, 2025
3f1ba35
removal of obselete code
d4v1d03 Apr 28, 2025
fa4f41f
fixed view/list bucket methods at sdk_ipc
d4v1d03 May 2, 2025
453da4b
added connections tests
d4v1d03 May 6, 2025
1f86670
fixing delete_bucket method
d4v1d03 May 19, 2025
3994ffe
WIP: on issue #36
manny-uncharted May 24, 2025
de92ad2
fixed file_info function to use correct protobuf method
d4v1d03 May 25, 2025
45c6233
file_info function modified and wqorking
d4v1d03 May 25, 2025
63fc667
REFACTOR: added type settings to connection.py
manny-uncharted May 26, 2025
1f2a99e
FIX: added type setting to the init method in connection.py
manny-uncharted May 26, 2025
6b6af63
REFACTOR: function name and variable name shared the same name within…
manny-uncharted May 26, 2025
70b9d94
REFACTOR: refactored sdk/dag.py adding type setting
manny-uncharted May 26, 2025
a5ee7fb
fixed the dynamic contract and node data retreival
d4v1d03 May 31, 2025
0b09e6e
ipc delete bucket testing
d4v1d03 May 31, 2025
a1c9491
type settings on erasure_code
manny-uncharted Jun 1, 2025
96cd1fb
delete bucket method works with working tests at tests directory
d4v1d03 Jun 1, 2025
a058fbb
Merge pull request #44 from d4v1d03/dev
Abhay-2811 Jun 4, 2025
d49e9d8
Merge branches 'feat/36' and 'dev' of github.com:manny-uncharted/akav…
manny-uncharted Jun 4, 2025
c3d9a98
file_info and list_files added with working tests
d4v1d03 Jun 6, 2025
98ee331
REFACTOR: refactored sdk, connection, erasure_code
manny-uncharted Jun 6, 2025
e07e805
REFACTOR: completed the sdk
manny-uncharted Jun 6, 2025
8faea3c
REFACTOR: refactored the make_gcm_cipher function to return both the …
manny-uncharted Jun 6, 2025
1c6647c
REFACTOR: removed local setup files
manny-uncharted Jun 6, 2025
307ff06
REFACTOR: done on encryption.py
manny-uncharted Jun 6, 2025
e4c05e3
REFACTOR: erasure code and test erasure code
manny-uncharted Jun 6, 2025
50b08ae
REFACTOR: completed on test_erasure_code.py
manny-uncharted Jun 6, 2025
74d28c7
REFACTOR: reverted erasure_code.py to using list comprehension
manny-uncharted Jun 6, 2025
d2baf08
REFACTOR: added type setting for test_dag.py
manny-uncharted Jun 6, 2025
29dbb54
REFACTOR: refactored the storage.py for type setting
manny-uncharted Jun 7, 2025
9c84a7d
REFACTOR: added type setting on policy.py
manny-uncharted Jun 7, 2025
1f2adc4
REFACTOR: refactored the access_manager with full type setting
manny-uncharted Jun 7, 2025
2f80aa7
WIP: on the client.py
manny-uncharted Jun 7, 2025
1e47722
FIX: added the fix for issue 47
manny-uncharted Jun 7, 2025
db4187d
REFACTOR: done for client and encryption
manny-uncharted Jun 7, 2025
141d737
REFACTOR: updated the extract_block_data function to handle the diffe…
manny-uncharted Jun 7, 2025
56ed38c
REFACTOR: on the dag file
manny-uncharted Jun 7, 2025
c5f3176
feat: adding a configurable retry decorator
Sahilgill24 Jun 8, 2025
864f178
updating web3 version && adding an .env.example for running tests
Sahilgill24 Jun 8, 2025
1cb061c
feat: changes in the retry decorator
Sahilgill24 Jun 8, 2025
db69f42
Merge pull request #48 from manny-uncharted/feat/47
Abhay-2811 Jun 9, 2025
e963f0a
Merge branch 'dev' of github.com:manny-uncharted/akavesdk-py into fea…
manny-uncharted Jun 9, 2025
b9ef6b6
WIP:
manny-uncharted Jun 9, 2025
d33d1bf
FIX: the duplication issues
manny-uncharted Jun 9, 2025
946a0ac
FIX: resolved issue with Duplicate class
manny-uncharted Jun 12, 2025
57fd8e8
added file_delete method with minor fixes
d4v1d03 Jun 15, 2025
2086fb7
Merge pull request #52 from manny-uncharted/feat/51
Abhay-2811 Jun 16, 2025
99623b3
fixed create_file_upload with working tests
d4v1d03 Jun 16, 2025
77bdfd1
WIP: type improvements on sdk ipc
manny-uncharted Jun 18, 2025
3010aa2
Merge branch 'dev' of github.com:manny-uncharted/akavesdk-py into fea…
manny-uncharted Jun 18, 2025
1d47808
Merge branch 'feat/53' into feat/36
manny-uncharted Jun 18, 2025
1feba13
FIX: removed duplicate new class in DAGRoot
manny-uncharted Jun 18, 2025
ec11a43
REFACTOR: updated type hints on sdk_streaming.py
manny-uncharted Jun 18, 2025
7234f4f
Merge branch 'dev' into dev
d4v1d03 Jun 19, 2025
36be2dc
added working chunk_upload code
d4v1d03 Jun 22, 2025
a29ba03
Merge remote-tracking branch 'origin/dev' into dev
d4v1d03 Jun 22, 2025
fc49424
REFACTOR: added more type hint support
manny-uncharted Jun 22, 2025
1034ee1
Merge pull request #49 from Sahilgill24/dev
Abhay-2811 Jun 23, 2025
abb92a4
Merge pull request #50 from d4v1d03/dev
Abhay-2811 Jun 23, 2025
e741f92
FEAT: in progress
manny-uncharted Jun 23, 2025
324a25b
Merge branch 'dev' of github.com:manny-uncharted/akavesdk-py into fea…
manny-uncharted Jun 23, 2025
da3a5eb
WIP: type done on storage.py
manny-uncharted Jun 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Python bytecode files
__pycache__/
*.py[cod]
*$py.class
pyproject.toml
poetry.lock
# Virtual environment directories
venv/
env/
.env
.venv/
ENV/
env.bak/
venv.bak/
NOTES
tests/.env


# Distribution / packaging
.Python
build/
dist/
*.egg-info/
*.eggs/
.eggs/

# IDEs and text editors
.idea/
.vscode/
*.swp
*.swo
*.bak
*.tmp
.mypy_cache/
scripts/
.pytest_cache/

# macOS files
.DS_Store
NOTES
*.toml
scripts/
*.lock
# Windows files
Thumbs.db
ehthumbs.db
NOTES
# Log files
*.log

# Jupyter Notebook checkpoints
.ipynb_checkpoints/

# Test and coverage reports
.coverage
.coverage.*
nosetests.xml
test_*.xml
pytest*
*.tox/
*.nox/
*.coverage
*.hypothesis/

# Django settings
*.log
*.pot
*.pyc
*.pyo
*.db
*.sqlite3

test.py
generate_protos.py
246 changes: 244 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,244 @@
# akavesdk-py
Python version of the Akavesdk
# Akave SDK for Python

The Akave SDK for Python provides a simple interface to interact with the Akave decentralized network.

## Installation

You can install the SDK using pip:

```bash
pip install akavesdk
```

Or install directly from GitHub:

```bash
pip install git+https://github.com/d4v1d03/akavesdk-py.git
```

## Authentication

The Akave SDK uses two main authentication methods:

1. **Blockchain-based authentication (IPC API)** - This uses Ethereum wallet private keys for IPC operations on the blockchain. This is required for operations that require blockchain transactions (creating buckets, managing file permissions, etc.).

2. **Standard API connection** - Basic operations like file uploads/downloads use gRPC connections to Akave nodes.

### Private Key Security

**Always be careful when dealing with your private key. Double-check that you're not hardcoding it anywhere or committing it to Git. Remember: anyone with access to your private key has complete control over your funds.**

Ensure you're not reusing a private key that's been deployed on other EVM chains. Each blockchain has its own attack vectors, and reusing keys across chains exposes you to cross-chain vulnerabilities. Keep separate keys to maintain isolation and protect your assets.

You can set up your authentication in several ways:

### Environment variables (recommended)

```bash
# Set these environment variables
export AKAVE_SDK_NODE="connect.akave.ai:5000" # Default Akave node endpoint for streaming operations
export AKAVE_IPC_NODE="connect.akave.ai:5500" # Default Akave node endpoint for IPC operations
export AKAVE_PRIVATE_KEY="your_ethereum_private_key" # Required for blockchain operations
export AKAVE_ENCRYPTION_KEY="your_32_byte_encryption_key" # Optional, for file encryption
```

#### Secure Private Key Management

For better security, store your private key in a file with restricted permissions:

```bash
# Create a secure key file
mkdir -p ~/.key
echo "your-private-key-content" > ~/.key/user.akvf.key
chmod 600 ~/.key/user.akvf.key

# Use the key file in your environment
export AKAVE_PRIVATE_KEY="$(cat ~/.key/user.akvf.key)"
```

### Direct initialization

```python
from akavesdk import SDK

# Initialize with explicit parameters
sdk = SDK(
address="connect.akave.ai:5000", # Akave endpoint for streaming operations
max_concurrency=10,
block_part_size=1 * 1024 * 1024, # 1MB
use_connection_pool=True,
private_key="your_ethereum_private_key", # Required for IPC API operations
encryption_key=b"your_32_byte_encryption_key", # Optional, for file encryption
ipc_address="connect.akave.ai:5500" # Akave endpoint for IPC operations (optional)
)
```

### Getting credentials

To get an Akave wallet address and add the chain to MetaMask:

1. Visit the [Akave Faucet](https://faucet.akave.ai) to connect and add the Akave chain to MetaMask
2. Request funds from the faucet
3. Export your private key from MetaMask (Settings -> Account details -> Export private key)

You can check your transactions on the [Akave Blockchain Explorer](https://explorer.akave.ai)

## Usage

### IPC API Usage (Blockchain-based, Recommended)

The IPC API is the recommended approach for interacting with Akave's decentralized storage. It provides access to Akave's smart contracts, enabling secure, blockchain-based bucket and file operations.

```python
from akavesdk import SDK

# Initialize the SDK with a private key
sdk = SDK(
address="connect.akave.ai:5500",
max_concurrency=10,
block_part_size=1 * 1024 * 1024, # 1MB
use_connection_pool=True,
private_key=os.environ.get("AKAVE_PRIVATE_KEY") # Required for IPC operations
)

try:
# Get IPC API interface
ipc = sdk.ipc()

# Create a bucket
bucket_result = ipc.create_bucket({}, "my-bucket")
print(f"Created bucket: {bucket_result.name}")

# List buckets
buckets = ipc.list_buckets({})
for bucket in buckets:
print(f"Bucket: {bucket.name}, Created: {bucket.created_at}")

# Upload a file (minimum file size is 127 bytes, max recommended test size: 100MB)
with open("my-file.txt", "rb") as f:
ipc.create_file_upload({}, "my-bucket", "my-file.txt")
file_meta = ipc.upload({}, "my-bucket", "my-file.txt", f)
print(f"Uploaded file: {file_meta.name}, Size: {file_meta.encoded_size} bytes")

# Download a file
with open("downloaded-file.txt", "wb") as f:
download = ipc.create_file_download({}, "my-bucket", "my-file.txt")
ipc.download({}, download, f)
print(f"Downloaded file with {len(download.chunks)} chunks")

# Delete a file
ipc.file_delete({}, "my-bucket", "my-file.txt")
print("File deleted successfully")

# Delete a bucket
ipc.delete_bucket({}, "my-bucket")
print("Bucket deleted successfully")
finally:
# Always close the connection when done
sdk.close()
```

### Streaming API Usage

```python
from akavesdk import SDK

# Initialize the SDK
sdk = SDK(
address="connect.akave.ai:5500",
max_concurrency=10,
block_part_size=1 * 1024 * 1024, # 1MB
use_connection_pool=True
)

try:
# Get streaming API
streaming = sdk.streaming_api()

# List files in a bucket
files = streaming.list_files({}, "my-bucket")
for file in files:
print(f"File: {file.name}, Size: {file.size} bytes")

# Get file info
file_info = streaming.file_info({}, "my-bucket", "my-file.txt")
print(f"File info: {file_info}")
finally:
sdk.close()
```

## File Size Requirements

- **Minimum file size**: 127 bytes
- **Maximum recommended test size**: 100MB

## Development

To set up the development environment:

1. Clone the repository:
```bash
git clone https://github.com/d4v1d03/akavesdk-py.git
cd akavesdk-py
```

2. Create a virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```

3. Install dependencies:
```bash
pip install -e .
```

4. Run tests:
```bash
pytest
```

## Node Address

The current public endpoint for the blockchain-based network is:
```
connect.akave.ai:5500
```

## Data Model

The Akave SDK for Python uses a set of Python dataclasses to represent the data structures used by the Akave network. These are Python equivalents of the Go structs used in the original SDK, adapted to follow Python conventions and best practices.

### Core Data Types

- **CIDType**: Content identifier for files, chunks, and blocks
- **TimestampType**: Union type that can represent timestamps in different formats (datetime, float, int)

### Bucket Operations

- **Bucket**: Represents a storage bucket in the Akave network
- **BucketCreateResult**: Result of a bucket creation operation

### File & Streaming Operations

- **FileMeta**: Contains metadata for a file (ID, size, timestamps)
- **Chunk**: Represents a piece of a file with its own metadata
- **Block**: The smallest unit of data storage, identified by a CID

### File Operations Models

- **FileListItem**: Used when listing files in a bucket
- **FileUpload/FileDownload**: Contains file metadata for upload/download operations
- **FileChunkUpload/FileChunkDownload**: Represents chunks during file transfer operations

### IPC Operations Models

- **IPCBucket**: Blockchain-based bucket representation
- **IPCFileMetaV2**: Extended file metadata for IPC operations
- **IPCFileChunkUploadV2**: Chunk metadata for IPC operations

The model structure is designed to be intuitive to Python developers while maintaining compatibility with the Akave API. All serialization/deserialization between Python objects and gRPC messages is handled automatically by the SDK.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
18 changes: 18 additions & 0 deletions akavesdk/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
import os

# Add private directory to path
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
PRIVATE_PATH = os.path.join(PROJECT_ROOT, "private")
if PRIVATE_PATH not in sys.path:
sys.path.append(PRIVATE_PATH)

# Import and expose main SDK classes
from sdk.sdk import SDK, SDKError, BucketCreateResult, Bucket
from sdk.sdk_streaming import StreamingAPI
from sdk.sdk_ipc import IPC
from sdk.erasure_code import ErasureCode

# Define what gets imported with "from akavesdk import *"
__all__ = ["SDK", "SDKError", "StreamingAPI", "IPC",
"BucketCreateResult", "Bucket", "ErasureCode"]
23 changes: 23 additions & 0 deletions akavesdk/akavesdk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
import os
# Add parent directory to path
current_dir = os.path.dirname(os.path.abspath(__file__))
if current_dir not in sys.path:
sys.path.append(current_dir)
# Add private directory to path
PRIVATE_PATH = os.path.join(current_dir, "private")
if PRIVATE_PATH not in sys.path:
sys.path.append(PRIVATE_PATH)
# Add private/pb directory to path specifically for protobuf imports
PB_PATH = os.path.join(PRIVATE_PATH, "pb")
if PB_PATH not in sys.path:
sys.path.append(PB_PATH)
# Import SDK classes using absolute imports
from sdk.sdk import SDK, BucketCreateResult, Bucket
from sdk.common import SDKError
from sdk.sdk_streaming import StreamingAPI
from sdk.sdk_ipc import IPC
from sdk.erasure_code import ErasureCode
# Export all classes
__all__ = ["SDK", "SDKError", "StreamingAPI", "IPC",
"BucketCreateResult", "Bucket", "ErasureCode"]
31 changes: 31 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[mypy]
python_version = 3.11
warn_return_any = True
warn_unused_configs = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
check_untyped_defs = True
disallow_untyped_decorators = True
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = False
warn_no_return = True
warn_unreachable = True

files = ./

exclude =
^__init__\.py$
_pb2\.py$
_pb2_grpc\.py$
\.proto$

[mypy-grpc.*]
ignore_missing_imports = True

[mypy-reedsolo.*]
ignore_missing_imports = True


[mypy-ipld_dag_pb.*]
ignore_missing_imports = True
Empty file added private/__init__.py
Empty file.
Loading