Midjourney: Permutation Prompts made easy with Python

Permutations is a technique to generate variations of prompts, using curly braces for that.

Vanessa Pacheco
3 min readOct 1, 2023

Here is what the Midjourney guide says about it:

Permutation Prompts allow you to quickly generate variations of a prompt with a single /imagine command. By including lists of options separated with commas ‘,’ within curly braces {} in your prompt, you can create multiple versions of a prompt with different combinations of those options.

a woman in the style of Charley Harper and ray eames

Okay, now — in the previous article (here) — I taught you to make a list of tokens to use in your prompt.

Now, let’s make it so that you can use these words to generate permutations.

Note: Permutations only work with fast hours.


#first: add your words here
a = ['''
linear perspective
- vibrant and textured brushwork
*colorful ink wash paintings
optical illusion paintings
colorful moebius
highly textured
conceptual painting**
indian pop culture
industrial urban scenes
apocalyptic
serge marshennikov
subdued tones
die brücke
concept art
''']

#now transform your list into strings
b = ''
for line in a:
b = line

In the next step, make sure you clean up your words nicely so you can create prompts from them in the next steps.

mystring = b

# Cleaning process
cleaned_string = (mystring.replace('**', '')
.replace('-', ' ')
.replace(' ', ' ')
.strip()
.replace('*', ''))

mylist = cleaned_string.split('\n')
#print(mylist)

Permutations are limited to 10 variations inside curly braces per time, so you will need to break our cleaned words into groups of 10 tokens.


slices = []

start = 0
end = len(mylist)
step = 10
for i in range(start, end, step):
x = i
sliced_list = mylist[x:x+step]
print(sliced_list)
slices.append(sliced_list)

Now, you can save your words, separated in groups of 10, to a file. This way you can copy them to Midjourney and start generating your images.

#now, you can save it into a file and exit the program.

filename = input('Enter new file name: ')

if filename.lower() in ['quit', 'exit']:
exit() # If user types 'quit' or 'exit', the program will end.

def format_slice(slice):
return '{' + ', '.join(slice) + '}\n\n'

with open(filename, 'w', encoding='utf-8') as file:
for slice in slices:
file.write(format_slice(slice))

In my case, I choose an object, I add “in the style of”, and include the list of words inside the curly brraces { }; like this:

/imagine a woman in the style of {linear perspective, vibrant and textured brushwork, colorful ink wash paintings, optical illusion paintings, elegant inking techniques, split toning, concept art, bold chromaticity, indian pop culture, laurie greasley}

By doing this, you will be able to get a wide variety of styles that will allow you to create better prompts and generate even more beautiful images.

Image 1 (vibrant and textured brushwork); image 2 (elegant inking techniques); image 3 (bold chromaticity).

--

--

Vanessa Pacheco

I'm a graphic designer and brand strategist, and now I'm excited to explore engineering-generated illustrations.