Skip to main content

Python SDK for Legnext AI API - Professional image and video generation using Midjourney models

Project description

Legnext Python SDK

Official Python client library for the Legnext AI API - Professional image and video generation using Midjourney models.

Features

  • Comprehensive API Coverage: Support for all Legnext endpoints
  • Type Safety: Full type hints with Pydantic models
  • Async Support: Both synchronous and asynchronous clients
  • Modern Design: Clean, intuitive API following OpenAI SDK patterns
  • Task Management: Built-in polling and webhook support
  • Error Handling: Robust error handling with automatic retries

Installation

pip install legnext

Or with uv:

uv pip install legnext

Quick Start

Basic Usage

from legnext import Client

client = Client(api_key="your-api-key")

# Generate an image
response = client.midjourney.diffusion(
    text="a beautiful sunset over mountains"
)

print(f"Job ID: {response.job_id}")
print(f"Status: {response.status}")

# Wait for completion
result = client.tasks.wait_for_completion(response.job_id)
print(f"Image URLs: {result.output.image_urls}")

Async Usage

import asyncio
from legnext import AsyncClient

async def main():
    async with AsyncClient(api_key="your-api-key") as client:
        response = await client.midjourney.diffusion(
            text="a futuristic cityscape"
        )
        result = await client.tasks.wait_for_completion(response.job_id)
        print(f"Generated: {result.output.image_urls}")

asyncio.run(main())

API Coverage

Midjourney Operations

Image Generation:

  • client.midjourney.diffusion(text) - Text to image generation (POST /diffusion)
  • client.midjourney.variation(job_id, image_no, type) - Create variations (POST /variation)
  • client.midjourney.upscale(job_id, image_no, type) - Upscale images (POST /upscale)
  • client.midjourney.reroll(job_id) - Re-generate with same prompt (POST /reroll)
  • client.midjourney.blend(image_urls) - Blend 2-5 images (POST /blend)
  • client.midjourney.describe(image_url) - Generate descriptions (POST /describe)
  • client.midjourney.shorten(prompt) - Optimize prompts (POST /shorten)
  • client.midjourney.pan(job_id, image_no, direction) - Extend in direction (POST /pan)
  • client.midjourney.outpaint(job_id, image_no) - Expand all directions (POST /outpaint)
  • client.midjourney.inpaint(job_id, image_no, mask, prompt) - Region editing (POST /inpaint)
  • client.midjourney.remix(job_id, image_no, prompt) - Transform with new prompt (POST /remix)
  • client.midjourney.edit(job_id, image_no, prompt) - Edit specific areas (POST /edit)
  • client.midjourney.upload_paint(image, prompt) - Advanced editing (POST /upload-paint)
  • client.midjourney.retexture(job_id, image_no, prompt) - Change textures (POST /retexture)
  • client.midjourney.remove_background(job_id, image_no) - Remove background (POST /remove-background)
  • client.midjourney.enhance(job_id, image_no) - Improve quality (POST /enhance)

Video Generation:

  • client.midjourney.video_diffusion(prompt, image_url, duration) - Generate video (POST /video-diffusion)
  • client.midjourney.extend_video(job_id) - Extend video (POST /extend-video)
  • client.midjourney.video_upscale(job_id) - Upscale video (POST /video-upscale)

Task Management

  • client.tasks.get() - Get task status
  • client.tasks.wait_for_completion() - Poll until complete

Documentation

Development

Setup

# Clone the repository
git clone https://github.com/your-org/legnext-python
cd legnext-python

# Install with dev dependencies
uv pip install -e ".[dev]"

Running Tests

pytest

Code Quality

# Format code
black src tests
isort src tests

# Lint
ruff check src tests

# Type check
mypy src

Requirements

  • Python 3.10+
  • httpx
  • pydantic

License

Apache License 2.0

Support

Changelog

See CHANGELOG.md for version history.

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

legnext-0.1.3.tar.gz (64.7 kB view details)

Uploaded Source

Built Distribution

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

legnext-0.1.3-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file legnext-0.1.3.tar.gz.

File metadata

  • Download URL: legnext-0.1.3.tar.gz
  • Upload date:
  • Size: 64.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for legnext-0.1.3.tar.gz
Algorithm Hash digest
SHA256 384b98729753e7b9455dea670dbdfb2e7a72246ff10f5b33e9437054d2261a5d
MD5 12058f6ae1b4379726a972ac1a333d0f
BLAKE2b-256 f028d5f5983010eb8e0414f44bb890d64818987894dd69ff1a20eceb1038818b

See more details on using hashes here.

File details

Details for the file legnext-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: legnext-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for legnext-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 718c02d1e788c4ac9c7c203ca58004489906e9499eb2dab4af22c8816a6bc956
MD5 724bdf2cf01782c77bac96b4a42b44c0
BLAKE2b-256 f55b6922df84787cc2220ec347f72c2c5c6a276e79fcfb28aa89f6f8cb7a44a4

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