Skip to main content

MidjourneyPy allows developers to easily use midjourney api without complications.

Project description

Installation

pip install midjourney-py

Midjourney

The Midjourney library provides a simplified and convenient way for developers to interact with the Midjourney API. With this library, developers can easily integrate Midjourney's powerful image processing capabilities into their applications without dealing with the complexities of manual API calls.

Key Features

  1. Simplified Interface: The APIRequest class abstracts away the complexities of API
  2. Authentication Handling: The library handles the authentication process, ensuring that API requests are properly authenticated with the provided API key.
  3. Endpoint Methods: The library provides intuitive methods for each API endpoint, making it easy to perform actions such as describing images, retrieving results, upscaling images, generating images based on prompts, and generating seeds for image generation.
  4. Response Handling: The library processes API responses and provides them in a structured format, simplifying the integration of API results into the application workflow.

Using the Imagine API

from midjourney import Midjourney

midjourney = Midjourney(
    api_key="API_KEY", callback_uri="")

# IMAGINE
seed = midjourney.imagine(prompt='cute mouse with hats')

result = midjourney.result(seed=seed)
if result.get('status') == 'completed':
    response = result
    print(response)
else:
    message = result.get('message')
    print(message)

Imagine Response

Note the task id generated will be passed to the result method to generate the imageUrl

{
  "taskId": "your_task_id"
}

when passed to the result method

{
  "status": "completed",
  "imageUrl": "https://cdn.discordapp.com/attachments/1124090271676772432/1126110757319360582/olivier_A_crying_white_kid_holding_a_blue_candy_splash_around_h_5b0a4099-f398-4118-8206-33f64c1a5589.png"
}

Using the Describe API

Describe images using the describe api from midjourney

from midjourney import Midjourney


midjourney = Midjourney(
    api_key="API_KEY", callback_uri="")

seed = midjourney.describe(
    image_path=r"C:\Users\Basit Ng\Downloads\rabbit.png")

result = midjourney.result(seed=seed)
if result.get('status') == 'completed':
    response = result
    print(response)
else:
    message = result.get('message')
    print(message)

Describe response

{
  "taskId": "task_id_generated"
}

when passed to the result method

{
  "status": "completed",
  "content": [
    "1️⃣ four images of a lion lying in water, in the style of cinematic sets, fantasy characters, cinematic lighting, ray tracing, soggy, naturalistic bird portraits, strong facial expression ",
    "2️⃣ four different images of a lion sitting in the water, in the style of vray tracing, realistic, emotive portraits, bokeh, [noah bradley](https://goo.gl/search?artist%20noah%20bradley), fairy tale, photorealistic compositions, 8k ",
    "3️⃣ lion portraits in the water, in the style of [raphael lacoste](https://goo.gl/search?artist%20raphael%20lacoste), bokeh, detailed character expressions, [charles spencelayh](https://goo.gl/search?artist%20charles%20spencelayh), emotional and dramatic scenes, nature inspired, fawncore ",
    "4️⃣ the lion  lion photo editing, lion phototutorials, lionphotography, portrait photography, animal photography, lion photo, in the style of vray tracing, wet-on-wet blending, multi-panel compositions, rendered in cinema4d, 8k 3d, fairy tale, bokeh"
  ]
}

Using the RESULT API

from midjourney import Midjourney


midjourney = Midjourney(
    api_key="API_KEY", callback_uri="")

seed = {
    "taskId": 'your_task_id',
}
result = midjourney.result(seed=seed)
if result.get('status') == 'completed':
    response = result
    print(response)
else:
    message = result.get('message')
    print(message)

Result response

{
  "imageURL": "https://cdn.discordapp.com/attachments/1124090271676772432/1125924854990917713/njho_Lion_king_8k_ultra_reality_in_a_rainy_zone___4410563673654_de36ac34-3209-4940-ab10-7178305ca75f.png"
}

Using the UPSCALE API

The response will contain the imageURL of the upscaled image.

from midjourney import Midjourney

midjourney = Midjourney(
    api_key="API_KEY", callback_uri="")

upscale = midjourney.upscale(
    task_id="the_task_id", position="2")

print(upscale)

Upscale response

{ "imageURL": "https://..........png" }

Using the SEED API

from midjourney import Midjourney

midjourney = Midjourney(
    api_key="AI_KEY", callback_uri="")

seed = midjourney.seed(task_id="the_task_id")

print(seed)

Seed response

{ "taskId": "https://..........png" }

If you prefer learning with visual you will love this video tutorial by Code Ninja

Watch video

Get a midjourney api to interact with midjourney-py

Get API key

The midjourney is created to make interacting with midjourney-py easy and more structured.

Wonderful Piece of art generated by the midjourney-py project

  1. A crying white kid holding a blue candy
  2. Upscaled Lion
  3. Lion 8k Ultra reality in a rainy zone
  4. A Lion King in a doom environment
  5. Cute Lion with hats
  6. 8k ultra reality girl
  7. Ajaga Abdulbasit generate a custom 8k picture of a coding ninja

Special Thanks

I would like to extend special thanks to John Coogan and the team at midjourney for their invaluable contributions in making the midjourney-py package accessible to others. Their dedication and expertise have greatly enhanced the functionality and usability of the package. By leveraging their knowledge and efforts, developers can now seamlessly integrate the Mid Journey API into their Python projects. Their commitment to open-source collaboration and their willingness to share their expertise have been instrumental in fostering a vibrant and supportive developer community. We extend our heartfelt appreciation to John Coogan and the entire midjourney team for their outstanding contributions and for making the midjourney-py package a valuable resource for developers.

Discord Community for Code Ninjas

Join the community

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

midjourney-py-1.0.4.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

midjourney_py-1.0.4-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file midjourney-py-1.0.4.tar.gz.

File metadata

  • Download URL: midjourney-py-1.0.4.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for midjourney-py-1.0.4.tar.gz
Algorithm Hash digest
SHA256 5408026d52876f40e6c790e4479777c63a1b3a51bd10b059bbc39a1a242c5fa4
MD5 ff3257294dad4c129142e6c31745fd97
BLAKE2b-256 dd6a8511b27c2fb8aba3e728e4fe4f9586579e08dc03284e035220c6e4ef70f6

See more details on using hashes here.

File details

Details for the file midjourney_py-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for midjourney_py-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 90fbfd4ebcef712b8f1f719639478cf53859daee469929abc9b9e56ca88e1e39
MD5 342f5b77d80f21b3b9730a5f4fc451d5
BLAKE2b-256 b8f8836d9cf0d8c7db3c5201d1005c1dc00b41f89117f69ab645c76abffe2a19

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page