Random Slugs
random-slugs is a user-friendly Python package that generates those random word slugs. This package is customizable and allows users to specify the parts of speech, categories of words, and the reproducibility.
Features
- Generate slugs with a specified number of words
- Customize the parts of speech and categories of words used
- Choose the format of the slug (
kebab-case,snake_caseorcamelCase) - Set a random seed for reproducibility
- Handle errors gracefully with custom exceptions
Installation
You can install random-slugs using pip:
pip install random-slugs
Usage
Here is a basic example of how to use the package:
from random_slugs import generate_slug
slug = generate_slug()
print(slug) # E.g. 'quick-brown-fox'
Customize the Slug
You can customize the slug generation by passing an options dictionary to the generate_slug function:
options = {
"parts_of_speech": ["adjectives", "nouns"],
"categories": {"adjectives": ["color"], "nouns": ["animal"]},
"format": "snake",
"seed": 42
}
slug = generate_slug(num_of_words=2, options=options)
print(slug) # E.g. : 'brown_fox'
API
generate_slug
generate_slug(num_of_words: int = 3, options: Options = None) -> str
Generates a random slug.
Parameters:
num_of_words(int): The number of words to include in the slug. Defaults to 3.options(Options): A dictionary of options to customize the slug generation.
Options:
-
parts_of_speech(List[str]): List of parts of speech to use. Must be one of:adjectives,nouns. -
categories(Dict): A dictionary mapping parts of speech to categories of words. E.g.{"adjectives": ["color"], "nouns": ["animal"]}.- Adjective Categories:
colorconditionemotionsizequantity
- Noun Categories:
animalcolorpokemonprofessiontechnologythingtransport
- Adjective Categories:
-
format(str): The format of the slug. Must be one of:kebab,snake,camel. Defaults tokebab. -
seed(int): The random seed value to use for reproducibility.
Returns:
str: The generated slug.
Total Unique Slugs
The total number of unique slugs that can be generated is calculated as follows:
from random_slugs import get_total_unique_slugs
total = get_total_unique_slugs()
print(total) # 6254859
Exceptions
RandomSlugsError: Base class for all exceptions in the package.RandomSlugConfigError: Exception for configuration errors.
Example
Here is a complete example that includes custom options and error handling:
from random_slugs import generate_slug, RandomSlugConfigError
options = {
"parts_of_speech": ["adjectives", "nouns"],
"categories": {"adjectives": ["size"], "nouns": ["animal"]},
"format": "camel",
"seed": "example_seed"
}
try:
slug = generate_slug(num_of_words=2, options=options)
print(slug) # E.g. "bigCat"
except RandomSlugConfigError as e:
print(f"Configuration error: {e}")
except RandomSlugsError as e:
print(f"Slug generation error: {e}")
Testing
You can run the test suite using the following command:
pytest tests
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for random-slugs 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| random_slugs-1.0.4.tar.gz | 9.3 kB | Without provenance | Details for random_slugs-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| random_slugs-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for random_slugs-1.0.4-py3-none-any.whl |
Total release size: 17.7 kB
Release files / random_slugs-1.0.4.tar.gz
| Download URL | random_slugs-1.0.4.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71e4e0708fa3e225e56cbe187d6e2fd97e910922368ff01b228c1eca7aea93ae
|
|
BLAKE2b-256 checksum How to use checksums |
e6ff0a5ad66016febee440f73ed4786e750040e8119a67da05c5f3036b416b49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.0
|
Release files / random_slugs-1.0.4-py3-none-any.whl
| Download URL | random_slugs-1.0.4-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0573169c01cd9e7dd5b024cb6c7d1c18b0ca13f4d0d48d977e02c8848febf7c8
|
|
BLAKE2b-256 checksum How to use checksums |
936828009fdeea1c7f80ad25b36e363bfc73cc7ea3c3afeeb612c0214140210d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.0
|
Security for random-slugs 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.