Random Name and Slug Generator
coolname is a Python library for generating random, human-readable names and slugs. It offers various functionalities, including generating names as sequences of words, creating slugs for use in web applications like Django, and generating names of specific lengths. The current version is 4.1.0, and it maintains an active development and release cadence.
Warnings
- breaking The `coolname` library requires Python 3.10 or newer. Installing on older Python versions will fail.
- gotcha Calling `generate_slug()` without arguments returns a name of random length, with a higher probability for 4-word names. If you require a consistent number of words, always specify the length (e.g., `generate_slug(2)`). Prepositions and articles ('of', 'from', 'the') are not counted towards the specified word length.
- gotcha Customizing word lists or generation rules requires using the `RandomGenerator` class and defining a configuration dictionary. This is more involved than using the simpler `generate()` or `generate_slug()` functions.
Install
-
pip install coolname
Imports
- generate_slug
from coolname import generate_slug
- generate
from coolname import generate
- RandomGenerator
from coolname import RandomGenerator
Quickstart
from coolname import generate_slug, generate, RandomGenerator
# Generate a random slug (default length, often 4 words)
print(f"Random slug: {generate_slug()}")
# Generate a slug with a specific number of words
print(f"2-word slug: {generate_slug(2)}")
print(f"3-word slug: {generate_slug(3)}")
# Generate a name as a list of words
name_words = generate()
print(f"Random name (list): {name_words}")
print(f"Joined name: {' '.join(name_words)}")
# Example of custom generator with custom word lists
custom_generator = RandomGenerator({
'all': {
'type': 'cartesian',
'lists': ['adjectives', 'animals']
},
'adjectives': {
'type': 'words',
'words': ['quick', 'sleepy', 'bright']
},
'animals': {
'type': 'words',
'words': ['fox', 'panda', 'owl']
}
})
print(f"Custom generated slug: {custom_generator.generate_slug()}")