Petname
Petname is a Python library that generates human-readable, random names for objects by combining adverbs, adjectives, and common nouns. It's often used for generating unique hostnames or container names, providing memorable and pronounceable identifiers. The current version is 2.9, with a release cadence driven by bug fixes, security patches, and wordlist updates.
Warnings
- breaking Critical DoS Vulnerability (CVE Candidate) in versions < 2.9: Word selection functions (`petname.adverb()`, `petname.adjective()`, `petname.name()`, and consequently `petname.generate()`) could hang indefinitely, consuming 100% CPU, if the `letters` (or `max_letters`) parameter was smaller than the shortest word in the internal word lists. For example, `petname.adverb(letters=3)` could cause an infinite loop in affected versions.
- gotcha Wordlist changes in version 2.8: Several words (e.g., `peacock`, `cockatoo`, `woodcock`) were removed from the internal names list to maintain consistency with upstream versions and avoid potentially awkward or unprofessional combinations. If your application relied on the exact composition of previous wordlists, this change might subtly alter generated names.
- gotcha The `letters` parameter (now `max_letters` in `generate()`) can still lead to no names being found if constrained too strictly (e.g., `max_letters=1` when no single-letter words exist), resulting in an empty string or IndexError. While the infinite loop is fixed in 2.9, extreme constraints can still yield unexpected or empty results.
Install
-
pip install petname
Imports
- generate
import petname petname.generate()
- Adjective
import petname petname.Adjective()
- Adverb
import petname petname.Adverb()
- Name
import petname petname.Name()
Quickstart
import petname
# Generate a two-word name (default)
name1 = petname.generate()
print(f"Generated name: {name1}")
# Generate a three-word name with a custom separator
name2 = petname.generate(3, '_')
print(f"Generated name: {name2}")
# Generate a single-word name with max letters
name3 = petname.generate(1, max_letters=5)
print(f"Generated name: {name3}")
# Generate words from specific categories
adjective = petname.Adjective()
print(f"Random adjective: {adjective}")