Skip to main content

SDK for FusionBrainAI API

Project description

FusionBrain SDK for Python

codecov License: MIT

This SDK provides a convenient way to interact with the FusionBrain API for generating images and other content. It includes both synchronous and asynchronous clients to suit different programming needs.

Features

  • Synchronous and Asynchronous clients.
  • Helper methods for checking pipeline status and availability.
  • Built-in mechanism for waiting for task completion with configurable retries.
  • Pydantic models for clear and safe data handling.

Installation

You can install the SDK using pip:

pip install fusionbrain-sdk-python

Getting Started

Authentication

To use the API, you need an API key and a secret. You can provide them in two ways:

  1. Directly to the client constructor:

    from fusionbrain_sdk_python import FBClient
    
    client = FBClient(x_key="YOUR_API_KEY", x_secret="YOUR_API_SECRET")
    
  2. Using environment variables:

    Create a .env file in your project root:

    FB_API_KEY="YOUR_API_KEY"
    FB_API_SECRET="YOUR_API_SECRET"
    

    The client will automatically pick up these variables.

Synchronous Usage Example

This example demonstrates the basic workflow for generating an image.

from fusionbrain_sdk_python import FBClient, PipelineType

# Initialize the client (assumes keys are in .env or passed directly)
client = FBClient()

# 1. Get a text-to-image pipeline
pipelines = client.get_pipelines_by_type(PipelineType.TEXT2IMAGE)
text2image_pipeline = pipelines[0]  # Using the first available pipeline
print(f"Using pipeline: {text2image_pipeline.name}")

# 2. Run the generation
run_result = client.run_pipeline(
    pipeline_id=text2image_pipeline.id,
    prompt="A red cat sitting on a table"
)

# 3. Wait for the final result
print(f"Task started with UUID: {run_result.uuid}")
final_status = client.wait_for_completion(
    request_id=run_result.uuid,
    initial_delay=run_result.status_time
)

if final_status.status == 'DONE':
    print("Generation successful!")
    # The result contains a list of base64-encoded images
    # print(final_status.result.files)
else:
    print(f"Generation failed with status: {final_status.status}")

Asynchronous Usage Example

The asynchronous client offers the same functionality for asyncio applications.

import asyncio
from fusionbrain_sdk_python import AsyncFBClient, PipelineType

async def main():
    async_client = AsyncFBClient()

    # 1. Get a text-to-image pipeline
    pipelines = await async_client.get_pipelines_by_type(PipelineType.TEXT2IMAGE)
    text2image_pipeline = pipelines[0]  # Using the first available pipeline
    print(f"Using pipeline: {text2image_pipeline.name}")

    # 2. Run the generation
    run_result = await async_client.run_pipeline(
        pipeline_id=text2image_pipeline.id,
        prompt="A blue bird flying in the sky"
    )

    # 3. Wait for the final result
    print(f"Task started with UUID: {run_result.uuid}")
    final_status = await async_client.wait_for_completion(
        request_id=run_result.uuid,
        initial_delay=run_result.status_time
    )

    if final_status.status == 'DONE':
        print("Generation successful!")
        # The result contains a list of base64-encoded images
        # print(final_status.result.files)
    else:
        print(f"Generation failed with status: {final_status.status}")

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

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

fusionbrain_sdk_python-0.1.0.tar.gz (19.9 MB view details)

Uploaded Source

Built Distribution

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

fusionbrain_sdk_python-0.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file fusionbrain_sdk_python-0.1.0.tar.gz.

File metadata

  • Download URL: fusionbrain_sdk_python-0.1.0.tar.gz
  • Upload date:
  • Size: 19.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for fusionbrain_sdk_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 68cd3e4146e60b5b8312e2516e779001a0a3b71bdedb7357130011d175c1dd3f
MD5 4439c4795fa1796ac6ff25c85e8c4161
BLAKE2b-256 89d8839862df4b1cd7e969fbc46ac1310dac53e3c4eb97ed3755d63233a54d42

See more details on using hashes here.

Provenance

The following attestation bundles were made for fusionbrain_sdk_python-0.1.0.tar.gz:

Publisher: ci.yml on FusionBrain26/fusionbrain-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fusionbrain_sdk_python-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fusionbrain_sdk_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cdb7cab5a87cd033495bc2576a5b4a620f1e9696b7fbd4e101330c4996ddb54
MD5 7b9cf75f3b81f325260b10e2d2d50a3d
BLAKE2b-256 662ed3040e61a455c03a65921ddbf53077889c6877152cdcc39a300867fa7164

See more details on using hashes here.

Provenance

The following attestation bundles were made for fusionbrain_sdk_python-0.1.0-py3-none-any.whl:

Publisher: ci.yml on FusionBrain26/fusionbrain-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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