Skip to main content

Python SDK for Flame distributed engine

Project description

Flame Python SDK

Python SDK for the Flame distributed computing framework.

Installation

pip install flamepy

Quick Start

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.

from flamepy import connect

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

Session

Represents a computing session with distributed resources.

# 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.

# 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.

# 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:

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:

# 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/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flamepy-0.3.0.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flamepy-0.3.0-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file flamepy-0.3.0.tar.gz.

File metadata

  • Download URL: flamepy-0.3.0.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for flamepy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 78401b5c9a13de9f03c6869bf0781c919241dd9b0ee784de4f4e6865b9281171
MD5 28a2b02dbc36156e2cd1c48c9b22d3c2
BLAKE2b-256 f2430a2d885766eb634eb5fda1eac69bb2acb402052c01e1634c28245cd6c880

See more details on using hashes here.

File details

Details for the file flamepy-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: flamepy-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 24.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for flamepy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 785a9134158c4699529f819990f605f205536ddf52cbb260a071f37fd7cf7975
MD5 d37b57ca36ed0922f72db2076c4b7c6d
BLAKE2b-256 d07fa454043ab91685339b30399f27a1cd0d210579960423a645e41e7b6a3a92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page