Skip to main content

Python package to generate random human-readable strings, e.g. project and experiment names

Project description

py-friendly-words

PyPI version PyPI - Downloads Tests

Python package to generate random human-readable strings, e.g. project and experiment names. The word lists are taken from glitchdomcom/friendly-words and the package provides a convenient way to access it, as well as methods to easily generate combinations.

The package is simple, limited, and over-engineered at the same time. In other words, a weekend night side project. If you need a stable package with more extensive customization, uniqueness guarantees, bigger and/or custom dictionaries, check out alexanderlukanin13/coolname.

Features

  • No extra dependencies
  • Optional preloading to avoid re-reading word list files
  • Customizable generation (see the examples below)
  • Custom separators
  • Can return as a list of words

Quick guide

Install with PIP: pip install friendlywords

import friendlywords as fw

# optional preloading, load all word lists into memory (~41KB)
# otherwise every generation would involve reading the files
fw.preload()

# generate random string that consists of N words (N > 0)
# if N is 1, the returned word is an object
# if N > 1, the first N-1 words are predicates
fw.generate(1)
>>> 'square'
fw.generate(4)
>>> 'southern florentine rain college'

# generate string that consists of a random predicate and random object
# p = predicate, o = object, t = team, c = collection
fw.generate('po')
>>> 'bittersweet curio'
fw.generate('pt')
>>> 'wood organization'
fw.generate('co')
>>> 'selection title'

# specify the separator
fw.generate('po', separator='-')
>>> 'better-tabletop'
fw.generate('ppp', separator=', ')
>>> 'elegant, skitter, sunny'
fw.generate(3, separator='/')
>>> 'winter/alkaline/handsaw' 

# return list of words instead of a string (ignores separator keyword)
fw.generate(5, as_list=True)
>>> ['laced', 'polyester', 'ossified', 'cyclic', 'chronometer']
fw.generate('pppoc', as_list=True)
>>> ['able', 'splendid', 'harvest', 'hedge', 'playlist']

# lists of all predicates, objects, teams or collections
fw.predicates, fw.objects, fw.teams, fw.collections
>>> ['windy', ...], ['turnip', ...], ['alliance', ...], ['album', ...]

Notes

  • You could make it reproducible by setting the random.seed().

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

friendlywords-1.1.3.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

friendlywords-1.1.3-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file friendlywords-1.1.3.tar.gz.

File metadata

  • Download URL: friendlywords-1.1.3.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for friendlywords-1.1.3.tar.gz
Algorithm Hash digest
SHA256 291454946b596f6d7814e0c409832a5c4352a13b65578ecc16836230fa19b851
MD5 e4786ffa170697346fdad7afb18482c2
BLAKE2b-256 0bcc0236704916a4cff8a4766c2d4ee7451eecdfa1bb198df3317f90f77793ed

See more details on using hashes here.

File details

Details for the file friendlywords-1.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for friendlywords-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 747dd2bd674dbf6a328bab6604cfd006c0b6b953adc12ba903a0e08fa0528639
MD5 48a635e97e87cbb1fe607d79bac31441
BLAKE2b-256 6af28cfd5843c295073ad8fa6f60a596204d0ed8fe8f1812a5ea8e3c71cf1c03

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page