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 Development

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 follow a given grammar
# 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.2.0.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

friendlywords-1.2.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: friendlywords-1.2.0.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for friendlywords-1.2.0.tar.gz
Algorithm Hash digest
SHA256 a90ea75775d0ecba71998b6c74a05f268b808d50ec2daf6ffa0f9f65715da7b9
MD5 62caaaf710efc7f967cbbd524c8c6ea0
BLAKE2b-256 f23ee3640a633e2a0130506719c2f65e348e764477c0458ea2cec0630a586ca3

See more details on using hashes here.

Provenance

The following attestation bundles were made for friendlywords-1.2.0.tar.gz:

Publisher: release.yml on the-lay/py-friendly-words

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: friendlywords-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for friendlywords-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e164a7fc112ebc88650067fcb2f30364d06d91cc9d3a1006088a11e0143a76a
MD5 58f27935801ba87ea1065ee1099e1c68
BLAKE2b-256 8c64cae966dbb097c91fa4401822743dd8618254968a06ea73f09a074f99a924

See more details on using hashes here.

Provenance

The following attestation bundles were made for friendlywords-1.2.0-py3-none-any.whl:

Publisher: release.yml on the-lay/py-friendly-words

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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