Skip to main content

A Python library for procedural fantasy name generation

Project description

Onymancer

A Python library for procedural generation of fantasy names using pattern-based generation.

Features

  • Pattern-Based Name Generation: Generate diverse fantasy names using customizable patterns with tokens for syllables, vowels, consonants, and more.
  • Token System: Supports various tokens like 's' for syllables, 'v' for vowels, 'c' for consonants, and special tokens for titles, insults, etc.
  • Grouping and Capitalization: Use angle brackets <> for groups, parentheses () for literals, and ! for capitalization.
  • JSON Token Loading: Load custom token sets from JSON files for extensible name generation.
  • Seeded Random Generation: Reproducible name generation with seed support.
  • Customizable Parameters: Fine-tune generation parameters for different name styles.

Installation

pip install onymancer

For development:

git clone https://github.com/Galfurian/onymancer.git
cd onymancer
pip install -e ".[dev]"

Quick Start

from onymancer import generate

# Generate a simple name
name = generate("s(dim)", seed=42)
print(name)  # e.g., "randim"

# Generate a fantasy name with capitalization
name = generate("!s!v!c", seed=123)
print(name)  # e.g., "Elira"

# Use groups for variety
name = generate("<s|v>c", seed=456)
print(name)  # e.g., "brin" or "acor"

Command Line Interface

For quick testing and batch generation, use the included CLI tool:

# Generate 5 fantasy names
python examples/generate.py --preset fantasy --count 5

# Use a custom pattern
python examples/generate.py --pattern "!s<v|l>!c!v" --count 3 --seed 42

# List available presets
python examples/generate.py --list-patterns

# Output as JSON
python examples/generate.py --preset title --count 2 --json

Patterns

The generate() function creates names based on input patterns. Patterns consist of various characters representing different types of random replacements. Everything else is emitted literally.

Tokens

  • s: Generic syllable
  • v: Vowel (a, e, i, o, u, y)
  • V: Vowel or vowel combination
  • c: Consonant
  • B: Consonant or combination suitable for word beginnings
  • C: Consonant or combination suitable anywhere in a word
  • i: Insult (humorous/derogatory words)
  • m: Mushy name (cute/affectionate names)
  • M: Mushy name ending
  • D: Consonant suited for "stupid" names
  • d: Syllable suited for "stupid" names
  • t: Title prefix (Master of, Ruler of, etc.)
  • T: Title suffix (the Endless, the Sea, etc.)

Special Characters

  • (): Literals - characters between parentheses are emitted literally
  • <>: Groups - random selection between options separated by |
  • !: Capitalization - capitalizes the next component

Examples

  • "s(dim)" → random syllable + "(dim)" → "thor(dim)"
  • "<s|v>" → either syllable or vowel → "brin" or "a"
  • "!s!v!c" → capitalized syllable + vowel + consonant → "Elira"
  • "<c|v|>" → consonant, vowel, or nothing

generate(pattern: str, seed: int) -> str

Main function for generating names.

Parameters:

  • pattern (str): The pattern defining the name structure
  • seed (int): Seed for random number generation

Returns:

  • str: The generated name

load_tokens_from_json(filename: str) -> bool

Load token definitions from a JSON file.

Parameters:

  • filename (str): Path to the JSON file

Returns:

  • bool: True if loading was successful

set_token(key: str, tokens: list[str]) -> None

Set the token list for a given key.

Parameters:

  • key (str): Single character token key
  • tokens (list[str]): List of possible replacements

set_tokens(tokens: dict[str, list[str]]) -> None

Set multiple token lists at once.

Parameters:

  • tokens (dict[str, list[str]]): Dictionary mapping keys to token lists

Usage Examples

See the examples/ directory for more detailed usage examples.

Development

Run tests:

pytest

Format code:

black src/onymancer tests
isort src/onymancer tests

License

MIT License. See LICENSE file.

Inspiration

This project is a Python port of the C++ namegen library, adapted for modern Python with type hints and comprehensive testing.

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

onymancer-0.1.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

onymancer-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: onymancer-0.1.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for onymancer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 481cb956a6006b6b9baf1029bdb597183b287c941206887d307824952d4f1858
MD5 499080949cc75dc56346ad998493fe46
BLAKE2b-256 4015223f79aeb12b332a16544b11dbb2cfc7d11c8426d496293fa16507a19aeb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: onymancer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for onymancer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 612adde1a4833a90ccd1c6717778f078db2d07df50f094664dde4536df859c62
MD5 f13f7dc932d67ff22acaea8428032679
BLAKE2b-256 0846d43052e1f1929b4ef12e2f2d74b7e042493a1b5cea398c43f6ccc9a9e9e0

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