Skip to main content

Python client for the unofficial MidJourney API.

Project description

中文说明README_CN.md

midjourney-python-api

This is a Python client for the unofficial MidJourney API, This implementation uses a Discord self bot, and utilizes this library: Merubokkusu/Discord-S.C.U.M. Please be aware that there might be a risk of being banned.

*** risky actions: issue #66

Key Features

  • Info
  • Imagine prompt
  • Image Upscale and Vectorize by label
  • All messages return via WebSocket, including banned words check and image processing
  • Auto reconnect WebSocket
  • status for execute command (imagine, interact), failed or success

Planned Features

  • Multi-account support
  • Full support for all MidJourney APIs

Setup, choose one of the following methods

by pip

# use pip, create visual env
python -m venv .venv 
pip install -r requirements.txt

by poetry

poetry install

Configuration

copy the config file and edit it, you can set all accounts in the config file

cp config.example.py config.py

Start the main Services

python main.py

Start test client to listen redis messages

python client.py

Start test client to send redis messages to test

python test.py

Technical Principles:

Multiple accounts need to be configured in config.py, each account requires the following fields: name, token, application_id, guild_id and channel_id.

The Python program will start two threads:

  1. One thread is used to receive messages from Redis and dispatch to subprocesses.

  2. The other thread is used to manage subprocesses.

The subprocess management thread will start one process for each account based on account configurations. Each process will have two threads:

  1. Redis receiving thread: receive tasks and assemble messages. The message queue name is `midjounery_task`. The message format is as follows:
{
  "cmd": string, command to execute, currently supports "imagine" and "interact",

  "args": array, arguments passed to the command, "imagine" only has one string "prompt", "interact" has two params "message_id" and "label",

  "channel_id": which channel to send the execution to, "imagine" can be omitted, program will randomly schedule across accounts, "interact" must pass the correct "channel_id".
}
  1. Redis sending thread: sends real-time WSS messages. The message queue name is `midjounery_notification`.

The program flow is as follows:

  1. Send messages from Redis task queue.

  2. The main process receives the message, and randomly selects a channel if "channel_id" is not present.

  3. Send to each subprocess through inter-process communication queue.

  4. Each account subprocess will receive this message, but only process tasks matching its own "channel_id", other tasks will be ignored.

  5. After receiving the task, the subprocess will call its internal function to execute.

  6. The execution result is listened via WSS, then sent externally via Redis queue.

workflow

workflow

program

program

Discussion

Donation

Loved the project? Condider buy me a coffee :D Kofi

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

midjounery_python_sdk-0.1.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

midjounery_python_sdk-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file midjounery_python_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: midjounery_python_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.7 Linux/5.15.146.1-microsoft-standard-WSL2

File hashes

Hashes for midjounery_python_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9c3765ee0e99eb10c80d9ea68d96089f23d712eeb6e8dcf093262a609512bc0e
MD5 b06ff5cfcb3a22d7d770c2aad37a93c4
BLAKE2b-256 210112c0fe157c16c1c94cbf1b42fc63379ccb607de3c7462295c2124977318e

See more details on using hashes here.

File details

Details for the file midjounery_python_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: midjounery_python_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.7 Linux/5.15.146.1-microsoft-standard-WSL2

File hashes

Hashes for midjounery_python_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68b37e591bdc10bc2042775c510fd18bdca9b9d33419588bc3869a6a172b628d
MD5 f471389a7aec613405ee1d15215744c2
BLAKE2b-256 4b0e5c59cea22057712f1c5f0302a577f239c59818cc9cebf9e02204c8e64d67

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