SDK for FusionBrainAI API
Project description
FusionBrain SDK for Python
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:
-
Directly to the client constructor:
from fusionbrain_sdk_python import FBClient client = FBClient(x_key="YOUR_API_KEY", x_secret="YOUR_API_SECRET")
-
Using environment variables:
Create a
.envfile 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68cd3e4146e60b5b8312e2516e779001a0a3b71bdedb7357130011d175c1dd3f
|
|
| MD5 |
4439c4795fa1796ac6ff25c85e8c4161
|
|
| BLAKE2b-256 |
89d8839862df4b1cd7e969fbc46ac1310dac53e3c4eb97ed3755d63233a54d42
|
Provenance
The following attestation bundles were made for fusionbrain_sdk_python-0.1.0.tar.gz:
Publisher:
ci.yml on FusionBrain26/fusionbrain-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fusionbrain_sdk_python-0.1.0.tar.gz -
Subject digest:
68cd3e4146e60b5b8312e2516e779001a0a3b71bdedb7357130011d175c1dd3f - Sigstore transparency entry: 429869911
- Sigstore integration time:
-
Permalink:
FusionBrain26/fusionbrain-sdk-python@05ba16b60a9fc3fe4ce0f63779c8d974cf5a723b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/FusionBrain26
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@05ba16b60a9fc3fe4ce0f63779c8d974cf5a723b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fusionbrain_sdk_python-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fusionbrain_sdk_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cdb7cab5a87cd033495bc2576a5b4a620f1e9696b7fbd4e101330c4996ddb54
|
|
| MD5 |
7b9cf75f3b81f325260b10e2d2d50a3d
|
|
| BLAKE2b-256 |
662ed3040e61a455c03a65921ddbf53077889c6877152cdcc39a300867fa7164
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fusionbrain_sdk_python-0.1.0-py3-none-any.whl -
Subject digest:
8cdb7cab5a87cd033495bc2576a5b4a620f1e9696b7fbd4e101330c4996ddb54 - Sigstore transparency entry: 429869920
- Sigstore integration time:
-
Permalink:
FusionBrain26/fusionbrain-sdk-python@05ba16b60a9fc3fe4ce0f63779c8d974cf5a723b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/FusionBrain26
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@05ba16b60a9fc3fe4ce0f63779c8d974cf5a723b -
Trigger Event:
workflow_dispatch
-
Statement type: