Composable, deterministic-friendly text-generation components for Python.
Reason this release was yanked:
includes spec was wrong
Project description
The Wordsmith Engine
The Wordsmith Engine is a composable, deterministic-friendly text-generation toolkit for Python.
It started as a port of the Swift package Wordsmith
(by the same author) and focuses on building
rich, varied text with small, reusable components.
What it is for
- Generating names for people, towns, ships, gangs, and creative works.
- Building simple language generators from reusable parts.
- Producing repeatable output with a seeded RNG.
Installation
Use PDM to install dependencies for development:
pdm install --group dev
Quickstart
from wordsmith import WorkTitle
print(WorkTitle()())
Core concepts
The Wordsmith Engine is centered around the Component type. Each component can render text
with a provided random number generator.
Operator DSL (preferred):
left | right: Join components with a space.left + right: Join components with no separator (useful for punctuation).
Key combinators:
text(*parts, sep=""): Join components with a custom separator.one_of(*options): Pick a random option.weighted_one_of((weight, option), ...): Weighted choice across many options.either(a, b, first_probability=0.5): Weighted choice between two options.maybe(*parts, probability=0.5): Optionally include text.
Common decorators on components:
.title_case()for title casing (with small-word rules)..capitalized()to capitalize all words..first_upper()for first-letter capitalization..prefixed_by_article()/.prefixed_by_determiner()for grammar helpers..possessive_form()for possessives.
Usage examples
import random
from wordsmith import Adjective, Noun, WorkTitle, either, maybe, one_of
rng = random.Random(42)
title = (
"The"
| maybe(Adjective())
| one_of("Journey", "Voyage", "Chronicles")
| "of"
| Noun().prefixed_by_article()
).title_case()
line = ("Once" | maybe("upon a time", probability=0.5)) + "."
print(title(rng))
print(line(rng))
print(WorkTitle()(rng))
Generators included
The Wordsmith Engine ships with a growing set of generators:
- Names:
GivenName,Surname,PersonName,WeirdName,AncientName - Locations:
TownName - Groups:
CriminalGangName,BandName - Vessels:
NauticalShipName - Works:
SimpleWorkTitle,UnusualWorkTitle,WorkTitle - Materials:
FictionalElementName,FictionalMineralName,ChemicalCompoundName - Specials:
ReadableUniqueIdentifier,ExoticCharacter
Deterministic output
All components accept a random.Random instance. If you want repeatable results,
pass a seeded RNG.
import random
from wordsmith import WorkTitle
rng = random.Random(1234)
print(WorkTitle()(rng))
print(WorkTitle()(rng))
Examples
Run any script under examples/ with PDM, for example:
pdm run python examples/work_titles.py
Development
- Install:
pdm install --group dev - Run tests:
pdm run pytest - Run lint:
pdm run lint
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wordsmith_engine-0.1.3.tar.gz.
File metadata
- Download URL: wordsmith_engine-0.1.3.tar.gz
- Upload date:
- Size: 64.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51f66aa46f012c6345d2fa2fe5805f5a90944a2a5b5dbc682d1ba7b3719cbf38
|
|
| MD5 |
fb1cee548bf6df3b84449522ac903998
|
|
| BLAKE2b-256 |
afa9fd784bb5939a062c424dc640cac7223afeaa3e3398580a3795dbdfa016a9
|
Provenance
The following attestation bundles were made for wordsmith_engine-0.1.3.tar.gz:
Publisher:
python-publish.yml on btfranklin/wordsmith-engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wordsmith_engine-0.1.3.tar.gz -
Subject digest:
51f66aa46f012c6345d2fa2fe5805f5a90944a2a5b5dbc682d1ba7b3719cbf38 - Sigstore transparency entry: 956038627
- Sigstore integration time:
-
Permalink:
btfranklin/wordsmith-engine@e9756f1d97af72390ea81f92aa3b2516f3258706 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/btfranklin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e9756f1d97af72390ea81f92aa3b2516f3258706 -
Trigger Event:
release
-
Statement type:
File details
Details for the file wordsmith_engine-0.1.3-py3-none-any.whl.
File metadata
- Download URL: wordsmith_engine-0.1.3-py3-none-any.whl
- Upload date:
- Size: 60.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af0e69d9aa77a0ab2b6591e639de9a7cf87a3af801146e871711f65600b639d3
|
|
| MD5 |
59567b65b94caa47ba66289910c7adee
|
|
| BLAKE2b-256 |
735414398943153b23d36e3eb3ee13b6689081a5293cb91404a992f3c1042583
|
Provenance
The following attestation bundles were made for wordsmith_engine-0.1.3-py3-none-any.whl:
Publisher:
python-publish.yml on btfranklin/wordsmith-engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wordsmith_engine-0.1.3-py3-none-any.whl -
Subject digest:
af0e69d9aa77a0ab2b6591e639de9a7cf87a3af801146e871711f65600b639d3 - Sigstore transparency entry: 956038634
- Sigstore integration time:
-
Permalink:
btfranklin/wordsmith-engine@e9756f1d97af72390ea81f92aa3b2516f3258706 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/btfranklin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e9756f1d97af72390ea81f92aa3b2516f3258706 -
Trigger Event:
release
-
Statement type: