Metadata-Version: 2.4
Name: sia_storage
Version: 0.4.1
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Rust
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Summary: Python SDK for interacting with the Sia decentralized storage network
Keywords: sia,decentralized,blockchain,depin,storage
Author: The Sia Foundation
License-Expression: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://devs.sia.storage/docs/quickstart
Project-URL: Homepage, https://sia.tech
Project-URL: Repository, https://github.com/SiaFoundation/sia-storage-sdk

# Sia Storage SDK for Python

Python bindings for Sia Storage, built with Rust and UniFFI.

## Requirements

- Python 3.9+

## Installation

### PyPI

```sh
pip install sia-storage
```

## Example

```python
import asyncio
from io import BytesIO

from sia_storage import (
    generate_recovery_phrase,
    set_logger,
    AppMeta,
    Builder,
    Logger,
    UploadOptions,
)


class PrintLogger(Logger):
    def debug(self, msg): print("DEBUG", msg)
    def info(self, msg): print("INFO", msg)
    def warning(self, msg): print("WARNING", msg)
    def error(self, msg): print("ERROR", msg)


set_logger(PrintLogger(), "debug")


async def main():
    app_id = b"\x01" * 32

    builder = Builder(
        "https://app.sia.storage",
        AppMeta(
            id=app_id,
            name="My App",
            description="App description",
            service_url="https://myapp.com",
            logo_url=None,
            callback_url=None,
        ),
    )
    await builder.request_connection()

    # Wait for user approval
    print(f"Please approve connection {builder.response_url()}")
    await builder.wait_for_approval()

    # Register with a recovery phrase
    mnemonic = generate_recovery_phrase()
    sdk = await builder.register(mnemonic)

    # Upload data
    upload = await sdk.upload_packed(UploadOptions())
    await upload.add(BytesIO(b"hello, world!"))
    objects = await upload.finalize()

    # Download data
    buf = BytesIO()
    await sdk.download(buf, objects[-1])


asyncio.run(main())
```

`PrintLogger` is a user-defined class that extends the SDK's `Logger` base class.

A complete working example is available in [examples/python/](../examples/python/).

## Local Development

```sh
cd python
pip install maturin

# Build and install the wheel
maturin develop

# Run the example
cd ../examples/python
python example.py
```

## License

MIT License - see [LICENSE](../LICENSE) for details.

