Metadata-Version: 2.4
Name: flamepy
Version: 0.3.0
Summary: Python SDK for Flame distributed engine
Author-email: XFLOPS Authors <support@xflops.io>
Project-URL: Homepage, https://xflops.io
Project-URL: Repository, https://github.com/xflops/flame
Project-URL: Issues, https://github.com/xflops/flame/issues
Keywords: distributed computing,flame,sdk
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: grpcio>=1.50.0
Requires-Dist: grpcio-tools>=1.50.0
Requires-Dist: protobuf>=4.21.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: isort>=5.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Dynamic: license-file

# Flame Python SDK

Python SDK for the Flame distributed computing framework.

## Installation

```bash
pip install flamepy
```

## Quick Start

```python
import asyncio
from flamepy import SessionAttributes, connect

async def main():
    # Connect to Flame service
    conn = await connect("http://localhost:8080")
    # Create a session
    session = await conn.create_session(SessionAttributes(
        application="flmlog",
        slots=2,
        common_data=b"shared data"
    ))
    
    # Create and run a task
    task = await session.create_task(b"task input data")
    
    # Watch task progress
    async for update in session.watch_task(task.id):
        print(f"Task {task.id}: {update.state}")
        if update.is_completed():
            break
    
    # Close session
    await session.close()
    await conn.close()

if __name__ == "__main__":
    asyncio.run(main())
```

## API Reference

### Connection

The main entry point for connecting to Flame services.

```python
from flamepy import connect

# Connect to a Flame service
conn = await connect("http://localhost:8080")
```

### Session

Represents a computing session with distributed resources.

```python
# Create a session
session = await conn.create_session(SessionAttributes(
    application="my-app",
    slots=2
))

# List sessions
sessions = await conn.list_sessions()

# Close a session
await session.close()
```

### Task

Represents individual computing tasks within a session.

```python
# Create a task
task = await session.create_task(b"input data")

# Get task status
task = await session.get_task(task.id)

# Watch task progress
async for update in session.watch_task(task.id):
    print(f"Task state: {update.state}")
    if update.is_completed():
        break
```

### Application

Manage distributed applications.

```python
# Register an application
await conn.register_application("my-app", {
    "shim": Shim.SHELL,
    "command": "python",
    "arguments": ["script.py"]
})

# List applications
apps = await conn.list_applications()
```

## Error Handling

The SDK provides custom exception types for different error scenarios:

```python
from flamepy import FlameError, FlameErrorCode

try:
    session = await conn.create_session(attrs)
except FlameError as e:
    if e.code == FlameErrorCode.INVALID_CONFIG:
        print("Configuration error:", e.message)
    elif e.code == FlameErrorCode.INVALID_STATE:
        print("State error:", e.message)
```

## Development

To set up the development environment:

```bash
# Clone the repository
git clone https://github.com/flame-sh/flame.git
cd flame/sdk/python

# Install in development mode
pip install -e .[dev]

# Run tests
pytest

# Format code
black flamepy/
isort flamepy/

# Type checking
mypy flamepy/
``` 
