Skip to main content

Python client for BrilliantAI APIs

Project description

BrilliantAI Python

A Python client for interacting with the BrilliantAI AI APIs for image and video generation.

Installation

pip install brilliantai-python

Usage

Authentication

You can authenticate using an API key directly or via an environment variable:

from brilliantai import BrilliantAI

# Option 1: API key directly
client = BrilliantAI(api_key="your_api_key", base_url="https://api.brilliantai.co")

# Option 2: Environment variable
# export BRILLIANTAI_API_KEY="your_api_key"
client = BrilliantAI()

Generating Images

# Generate an image
image = client.generate_image(
    model="glimmer-v1",
    prompt="a beautiful landscape",
    aspect_ratio=BrilliantAI.AspectRatio.LANDSCAPE_16_9,
    image_format=BrilliantAI.ImageFormat.PNG,
    seed=42
)

# Save the image
image.save("landscape")  # Saves as "landscape.png"

A beautiful landscape

Generating Videos

# Generate a video
video = client.generate_video(
    model="wan-v1",
    prompt="a flowing river",
    quality=BrilliantAI.VideoQuality.HIGH,
    fps=30
)

# Save the video
video.save("river")  # Saves as "river.mp4"

Watch the generated video

API Reference

BrilliantAI

BrilliantAI(api_key=None, base_url="https://api.brilliantai.co", timeout=1200)

Creates a new client instance.

Parameters:

  • api_key (Optional[str]): API key for authentication. If not provided, will attempt to use the BRILLIANTAI_API_KEY environment variable.
  • base_url (str): Base URL for the API.
  • timeout (int): Request timeout in seconds. Default is 1200 (20 minutes).

generate_image(model, prompt, aspect_ratio=AspectRatio.SQUARE, image_format=ImageFormat.WEBP, seed=None)

Generates an image based on the given prompt.

Parameters:

  • model (str): The model to use for generation.
  • prompt (str): The prompt describing the image.
  • aspect_ratio (BrilliantAI.AspectRatio): The aspect ratio of the generated image.
  • image_format (BrilliantAI.ImageFormat): The format of the generated image.
  • seed (Optional[int]): Random seed for reproducibility.

Returns:

  • Media: Media object containing the generated image.

generate_video(model, prompt, quality=BrilliantAI.VideQuality.HIGH, fps=25)

Generates a video based on the given prompt.

Parameters:

  • model (str): The model to use for generation.
  • prompt (str): The prompt describing the video.
  • quality (BrilliantAI.VideoQuality): The quality of the video (LOW, QUALITY, HIGH).
  • fps (int): Frames per second of the video.

Returns:

  • Media: Media object containing the generated video.

Media

Media(base64_data, format)

Represents media data (images or videos).

Methods:

  • save(path): Saves the media to the specified path. If no extension is provided, the correct one will be added based on the format.

Exceptions

APIError(status_code, message)

Raised when the API returns an error.

License

MIT

Development

Setup Development Environment

  1. Clone the repository:
git clone https://github.com/brilliantai/brilliantai-python.git
cd BrilliantAI
  1. Install development dependencies:
# Using pip
pip install -e . -r dev-requirements.txt

# Using uv (recommended)
uv pip install -e . -r dev-requirements.txt

Running Tests

Run tests with the provided script:

./scripts/run_tests.sh

Or run the commands individually:

# Run linting
ruff check .

# Run tests with coverage
pytest --cov=BrilliantAI

CI/CD

This project uses GitHub Actions for continuous integration and deployment:

  • Tests are automatically run on all pull requests and pushes to the main branch
  • When a new release is created, the package is automatically built and published to PyPI

Contributing

Contributions are welcome! Here's how you can contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests to ensure everything works
  5. Commit your changes (git commit -m 'Add some amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Please make sure your code passes all tests and linting checks before submitting a pull request.

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

brilliantai_python-0.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

brilliantai_python-0.1.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file brilliantai_python-0.1.2.tar.gz.

File metadata

  • Download URL: brilliantai_python-0.1.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for brilliantai_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bcd9a87169abe70febb274bac8b8087e1c31c23144d63c58224ca5fc3bb60614
MD5 0d7b3d3282c85da6360beb2a1c3e246c
BLAKE2b-256 fa4b3b2c5fd6f6324ce7c9e8bf2d49bb5457144fbb4c2c140ff972e613c0c2ee

See more details on using hashes here.

File details

Details for the file brilliantai_python-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for brilliantai_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bc2aab5a8ddbbd022617c491619dfee65be09437e7d8504d75efb0d3aef283d6
MD5 51a0ac4f949a7ef3befc65115dbf0ea3
BLAKE2b-256 680beb1cf7523cee0efb28671031b0373bfe298985f6c54e83e8ee0b7ebfcf49

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