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:
-
One thread is used to receive messages from Redis and dispatch to subprocesses.
-
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:
- 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".
}
- Redis sending thread: sends real-time WSS messages. The message queue name is `midjounery_notification`.
The program flow is as follows:
-
Send messages from Redis task queue.
-
The main process receives the message, and randomly selects a channel if "channel_id" is not present.
-
Send to each subprocess through inter-process communication queue.
-
Each account subprocess will receive this message, but only process tasks matching its own "channel_id", other tasks will be ignored.
-
After receiving the task, the subprocess will call its internal function to execute.
-
The execution result is listened via WSS, then sent externally via Redis queue.
workflow
program
Discussion
- discord : https://discord.gg/AJSGUVeMd9
Donation
Loved the project? Condider buy me a coffee :D Kofi
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for midjounery_python_sdk-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c3765ee0e99eb10c80d9ea68d96089f23d712eeb6e8dcf093262a609512bc0e |
|
MD5 | b06ff5cfcb3a22d7d770c2aad37a93c4 |
|
BLAKE2b-256 | 210112c0fe157c16c1c94cbf1b42fc63379ccb607de3c7462295c2124977318e |
Hashes for midjounery_python_sdk-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68b37e591bdc10bc2042775c510fd18bdca9b9d33419588bc3869a6a172b628d |
|
MD5 | f471389a7aec613405ee1d15215744c2 |
|
BLAKE2b-256 | 4b0e5c59cea22057712f1c5f0302a577f239c59818cc9cebf9e02204c8e64d67 |