Skip to main content

Midjourney SDK for interacting with Midjourney Discord. Get imagine. All options possible.

Project description

Midjourney Python SDK

PyPI version License: MIT Python Version

The Midjourney Python SDK is a powerful and easy-to-use library that allows you to interact with the Midjourney AI image generation platform directly from your Python code. With this SDK, you can generate stunning images, upscale them, and customize the generation process using various parameters and options.

How use it the Midjourney SDK

What is Midjourney?

Midjourney is an AI-powered image generation platform that creates highly detailed and imaginative images from textual descriptions. It utilizes advanced machine learning techniques to interpret and visualize prompts, enabling users to generate unique and captivating artwork, illustrations, and designs.

Installation

You can install the Midjourney Python SDK using pip:

pip install midjourney-sdk-py

Usage

To use the Midjourney Python SDK, you need to obtain your discord_channel_id and discord_user_token. Here's how you can retrieve them:

discord_channel_id:

Navigate to the Discord channel where you want to use the Midjourney bot. The URL of the channel will look like this: https://discord.com/channels/yyyyyyyyy/xXXXXxxxXxXxxXxx Copy the last part of the URL (xXXXXxxxXxXxxXxx), which represents your discord_channel_id.

discord_user_token:

Open your Discord application and navigate to https://discord.com/channels/@me. Open the browser's developer console (usually by pressing F12). Go to the "Network" tab and select the "XHR" filter. Refresh the page and click on the "@me" request. In the "Headers" section, look for the "Authorization" header and copy the token value.

A picture is worth a thousand words

An image to illustrate the process to get the discord_channel_id and discord_user_token. How get Discord ID

Once you have the discord_channel_id and discord_user_token, you can start using the Midjourney Python SDK. Here's a basic example of how to generate an image using the SDK:

from midjourney_sdk_py import Midjourney

discord_channel_id = "YOUR_DISCORD_CHANNEL_ID"
discord_user_token = "YOUR_DISCORD_USER_TOKEN"

midjourney = Midjourney(discord_channel_id, discord_user_token)

prompt = "A teddy bear in Scotland, holding a French flag, with a Scottish landscape in the background, in a comic style"
options = {
    "ar": "3:2",
    "v": "6.0",
}

message = midjourney.generate(prompt, options)

print(message['upscaled_photo_url'])

The SDK provides various methods and options to customize the image generation process, such as:

imagine: Generate an initial image based on a prompt. upscale: Upscale a previously generated image. get_imagine: Retrieve a previously generated image. get_upscale: Retrieve an upscaled version of a generated image. get_parameter_from_prompt: Extract parameters and sources from a prompt string.

You can explore the available options and parameters to fine-tune the generated images according to your requirements. The SDK supports aspect ratios, chaos levels, quality settings, styles, negative prompting, and more.

Extracting Parameters from Prompts

The get_parameter_from_prompt method allows you to extract parameters and sources from a prompt string. This can be incredibly useful when you have a complete prompt string containing options and image sources, and you want to separate them for more flexible usage. Here's an example of how to use get_parameter_from_prompt:

from midjourney_sdk_py import Midjourney

discord_channel_id = "YOUR_DISCORD_CHANNEL_ID"
discord_user_token = "YOUR_DISCORD_USER_TOKEN"

midjourney = Midjourney(discord_channel_id, discord_user_token)

prompt = "An illustration of A teddy bear in scotland, french flag in the hand, scotland landscape, comics --ar 3:2 --v 6.0 --turbo --sref http://example.com/style1.jpg, http://example.com/style2.jpg --cref http://example.com/character1.jpg, http://example.com/character2.jpg"

options, sources, cleaned_prompt = midjourney.get_parameter_from_prompt(prompt)

print("Options:", options)
print("Sources:", sources)
print("Cleaned Prompt:", cleaned_prompt)

message = midjourney.generate(cleaned_prompt, options, sources)

print(message['upscaled_photo_url'])

License

This project is licensed under the MIT License. See the LICENSE file for more details. Acknowledgments

Midjourney for providing the incredible AI image generation platform. The developers and contributors of the Midjourney Python SDK for their hard work and dedication.

Feedback and Support

If you have any questions, suggestions, or issues regarding the Midjourney Python SDK, please feel free to open an issue on the GitHub repository. We appreciate your feedback and will do our best to assist you. Happy image generation with the Midjourney Python SDK!

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-sdk-py-1.0.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

midjourney_sdk_py-1.0.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file midjourney-sdk-py-1.0.1.tar.gz.

File metadata

  • Download URL: midjourney-sdk-py-1.0.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for midjourney-sdk-py-1.0.1.tar.gz
Algorithm Hash digest
SHA256 dcdb2e5fc37ec2f40e306f929dda38d31363153ca2c0862f78705cda85f80aaa
MD5 22a287ece72f749b21699b9b7503f97f
BLAKE2b-256 697414f2f2413310e6dc8ccc9432c561f48d7b5bff6790f1585f330f35bff1c9

See more details on using hashes here.

File details

Details for the file midjourney_sdk_py-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for midjourney_sdk_py-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c287fc13d362c4b371a87537ce8d8b62a1395921bb1d69e9fe67239d6acdfac
MD5 c1c9a8da091e8ce40f67796c084efbb5
BLAKE2b-256 7519f4a08ce4c20726fdb2eb60969e499d47f99486b47f27cd3b371ccde3104e

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