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.4.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.4-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: legnext-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 76a7b429a00771846bbcbdff8414dab81bb7ce6ab9871655abc9669b4ebdc2cf
MD5 7bf3cbe7598ffe06e693c373849195d3
BLAKE2b-256 d70d26820bd698a9e10973c069efbafcb2da2a9a6947b555f91124811dbc346b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: legnext-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5990ec3b6bc516444cf97ec438fcfea50ab8e4024af8ad9746a241cd082fb5d9
MD5 ef2947e7fc338df44e77599934d899e5
BLAKE2b-256 c7abfd93300ffcfc23d4324f62971619a8ef99b9402a4e256cd8bdaebd801376

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