### Example Text File for Phrases Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md This example shows a text file where lines with multiple words are treated as phrases. The file content is used to generate a 'phrases' list in the Coolname configuration. ```text one two # Here is the phrase three four ``` -------------------------------- ### Install coolname Package Source: https://github.com/alexanderlukanin13/coolname/blob/master/README.rst Command to install the coolname package using pip. ```bash pip install coolname ``` -------------------------------- ### Command Line Usage Source: https://github.com/alexanderlukanin13/coolname/blob/master/README.rst Examples of using the 'coolname' command-line tool to generate slugs with custom separators and counts. ```bash $ coolname prophetic-tireless-bullfrog-of-novelty $ coolname 3 -n 2 -s '_' wildebeest_of_original_champagne ara_of_imminent_luck ``` -------------------------------- ### Generate Slug from Command Line Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/index.md Example of using the `coolname` command-line tool to generate a default slug. ```bash $ coolname prophetic-tireless-bullfrog-of-novelty ``` -------------------------------- ### Text File Format for Words with Comments and Options Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md This example shows the basic text file format for defining words, including comments and inline options. Options like max_length must appear at the beginning of the file. ```text # comment one two # inline comment # blank lines are OK three ``` -------------------------------- ### Cartesian List Generation Example Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md Demonstrates generating slugs using a Cartesian list configuration with custom rules. ```python >>> from coolname import RandomGenerator >>> generator = RandomGenerator(config) >>> for i in range(3): ... print(generator.generate_slug()) ... my-banana-is-sweet my-apple-is-green my-apple-is-sour ``` -------------------------------- ### Invalid Custom Generator Configuration Example Source: https://github.com/alexanderlukanin13/coolname/blob/master/HISTORY.rst Shows an example of an invalid configuration for a custom generator in Coolname. This configuration uses arbitrary types (integers) within phrase lists, which is strictly forbidden and will raise an exception. ```json { "all": { "type": "phrases", "phrases": [[1,2], [3,4]]} # don't do this } ``` -------------------------------- ### Number Rule Generation Example Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md Demonstrates generating slugs that include random numbers using a Cartesian list configuration. ```python >>> from coolname import RandomGenerator >>> generator = RandomGenerator(config) >>> for i in range(3): ... print(generator.generate_slug()) ... cat-798 bird-931 cat-83 ``` -------------------------------- ### Constant Rule Example Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md Defines a rule that always returns a specific, fixed value. Useful for prepositions or other static words. ```python 'of': { 'type': 'const', 'value': 'of' } ``` -------------------------------- ### Words List Rule Example Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md Defines a rule to choose a random word from a list with equal probability. Supports parameters for whitespace handling. ```python # This will produce random color 'color': { 'type': 'words', 'words': ['red', 'green', 'yellow'] }, # This will produce random taste 'taste': { 'type': 'words', 'words': ['sweet', 'sour'] }, # This will produce random fruit 'fruit': { 'type': 'words', 'words': ['apple', 'banana'] } ``` -------------------------------- ### Cartesian List with Number Rule Configuration Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md Example configuration combining a Cartesian list with a number rule to generate slugs containing both words and numbers. ```python 'all': { 'type': 'cartesian', 'lists': ['word', 'number'] }, 'word': { 'type': 'words', 'words': ['dog', 'cat', 'bird'] }, 'number': { 'type': 'number', 'digits': '3' # default is 3 if omitted; min=1, max=7 } ``` -------------------------------- ### Number Rule Example Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md Defines a rule to generate a random number with a specified number of digits. The 'digits' parameter controls the length. ```python 'number': { 'type': 'number', 'digits': '3' # default is 3 if omitted; min=1, max=7 } ``` -------------------------------- ### Get Total Combinations Count Source: https://github.com/alexanderlukanin13/coolname/blob/master/README.rst Retrieves the total number of possible name combinations supported by the generator. ```python >>> from coolname import get_combinations_count >>> get_combinations_count() 83930205085 ``` -------------------------------- ### Phrases List Rule Example Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md Defines a rule to choose a random phrase from a list, where each element can be one or more words. Phrases can be strings or lists of words. ```python # This will produce random color 'color': { 'type': 'phrases', 'phrases': ['red', 'green', 'navy blue', ['royal', 'purple']] } ``` -------------------------------- ### Generated JSON Rule for Phrases Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md This JSON output represents the rule generated from the example text file. Lines with single words become single-element arrays, while lines with multiple words are parsed into arrays of words, forming a 'phrases' list. ```json { "type": "phrases", "phrases": [ ["one"], ["two"], ["three", "four"] ] } ``` -------------------------------- ### Nested List Rule Example Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md Defines a rule to choose a random item from child lists, with probability proportional to the child list's length. Child lists can be of any type. ```python # This will produce random adjective: color or taste 'adjective': { 'type': 'nested', 'lists': ['color', 'taste'] } ``` -------------------------------- ### Cartesian List Rule Example Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md Defines a rule that produces a list by choosing one item from each child list, similar to a slot machine. Avoid nesting Cartesian lists. ```python # This will produce a random list of 4 words, # for example: ['my', 'banana', 'is', 'sweet'] 'all': { 'type': 'cartesian', 'lists': ['my', 'fruit', 'is', 'adjective'] }, # Additional const definitions 'is': { 'type': 'const', 'value': 'is' }, 'my': { 'type': 'const', 'value': 'my' } ``` -------------------------------- ### Python Initialization with Loaded Configuration Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md This Python code shows how to load a configuration from a directory using load_config and then initialize a RandomGenerator. This is useful for managing larger configurations. ```python from coolname.loader import load_config config = load_config('./my_config') from coolname import RandomGenerator g = RandomGenerator(config) g.generate_slug() ``` -------------------------------- ### Configuration file comments in TXT format (5.0.0) Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/history.md Configuration files in *.txt format now support comments after a word/phrase, similar to Python's style. ```default >>> # this was allowed before >>> one >>> two # this is now allowed too ``` -------------------------------- ### Python Initialization with Inline Configuration Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md This Python code demonstrates initializing a RandomGenerator with an inline configuration dictionary. It generates a slug based on adjective and noun lists. ```python from coolname import RandomGenerator gconfig = {'all': {'type': 'cartesian', 'lists': ['adjective', 'noun']}, 'adjective': {'type':'words', 'words':['crouching','hidden']}, 'noun': {'type': 'words', 'words': ['tiger', 'dragon']}} g = RandomGenerator(config) g.generate_slug() ``` -------------------------------- ### Initialize RandomGenerator with Configuration Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/randomization.md This snippet demonstrates how to initialize a `RandomGenerator` with a specific configuration. The configuration defines the structure and possible words/phrases for generating names, influencing the total number of combinations. ```python config = { 'all': { 'type': 'cartesian', 'lists': ['price', 'color', 'object'] }, # 2 items 'price': { 'type': 'words', 'words': ['cheap', 'expensive'] }, # 3 items 'color': { 'type': 'words', 'words': ['black', 'white', 'red'] }, # 5 + 6 = 11 items 'object': { 'type': 'nested', 'lists': ['footwear', 'hat'] }, # 5 items 'footwear': { 'type': 'words', 'words': ['shoes', 'boots', 'sandals', 'sneakers', 'socks'] }, # 6 items 'hat': { 'type': 'phrases', 'phrases': ['top hat', 'fedora', 'beret', 'cricket cap', 'panama', 'sombrero'] } } import coolname generator = coolname.RandomGenerator(config) ``` -------------------------------- ### Configuration File Comments Source: https://github.com/alexanderlukanin13/coolname/blob/master/HISTORY.rst Illustrates how comments can be added to configuration files (`.txt` format) in Coolname. Comments are Python-style, appearing after a word or phrase on the same line. ```text # this was allowed before one two # this is now allowed too ``` -------------------------------- ### Text File Format with max_length Option Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md This text file demonstrates how to specify configuration options, such as max_length, at the beginning of a word list file. This is equivalent to setting the option in a JSON configuration. ```text max_length = 13 ``` -------------------------------- ### Generate and Format Random Name Source: https://github.com/alexanderlukanin13/coolname/blob/master/README.rst Demonstrates joining generated name words with spaces or capitalizing each word. ```python >>> ' '.join(generate()) 'limber transparent toad of luck' >>> ''.join(x.capitalize() for x in generate()) 'CalmRefreshingTerrierOfAttraction' ``` -------------------------------- ### Importing generate_slug and RandomGenerator (Old vs. New) Source: https://github.com/alexanderlukanin13/coolname/blob/master/HISTORY.rst Demonstrates the change in import paths for `generate_slug` and `RandomGenerator` between older and newer versions of the Coolname library. The newer versions place these directly in the top-level `coolname` namespace. ```python >>> from coolname import generate_slug, RandomGenerator >>> generate_slug > >>> RandomGenerator ``` ```python >>> generate_slug > >>> RandomGenerator ``` -------------------------------- ### Configuration Rules Structure Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md The configuration is a flat dictionary of rules, where each rule has an ID and specifies its type and other parameters. ```python { '': { 'comment': 'Some info about this rule. Not mandatory.', 'type': '', # additional fields, depending on type }, ... } ``` -------------------------------- ### Using hashlib.md5 with usedforsecurity=False (2.1.0) Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/history.md This snippet demonstrates the use of hashlib.md5 with the usedforsecurity=False argument to support OpenSSL FIPS compliance. ```python >>> import hashlib >>> hashlib.md5(..., usedforsecurity=False) ``` -------------------------------- ### Capitalize and Join Generated Name Words Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/index.md Shows how to capitalize each word from a generated name list and join them without spaces. ```python >>> ''.join(x.capitalize() for x in generate()) 'CalmRefreshingTerrierOfAttraction' ``` -------------------------------- ### Custom generator configuration with phrase lists (1.0.4) Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/history.md Phrase lists provide more flexibility when creating custom generators, allowing for more complex word or phrase combinations. ```python >>> # [Phrase lists](https://coolname.readthedocs.io/en/latest/customization.html#phrases-list) >>> # give you even more freedom when creating custom generators. ``` -------------------------------- ### Join Generated Name Words Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/index.md Demonstrates joining the words from a generated name list into a space-separated string. ```python >>> ' '.join(generate()) 'limber transparent toad of luck' ``` -------------------------------- ### Setting Environment Variables in Python Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/environment-variables.md Configure environment variables from Python code before importing Coolname to use a custom generator. ```python import os os.environ['COOLNAME_DATA_MODULE'] = 'some.module' from coolname import generate_slug ``` -------------------------------- ### Custom generator rendering with render() and write() (5.0.0) Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/history.md Custom generators can now be rendered into text representation using render() and write() methods, which is useful for debugging and logging. ```python >>> # Custom generator can be rendered into text representation via >>> # render() and write(). >>> # Useful in debugging and logging. ``` -------------------------------- ### JSON Configuration with max_length for words Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md This JSON configuration defines a word list with a maximum character length of 5 for each word. It will fail if any word exceeds this limit. ```json { "all": { "type": "words", "words": ["cat", "tiger", "jaguar"], "max_length": 5 } } ``` -------------------------------- ### Seeding or replacing the random.Random instance (1.0.4) Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/history.md This snippet explains how to seed or replace the underlying random.Random instance for custom randomization in generators. Refer to the documentation for more details on Randomization. ```python >>> # You can seed or even replace the underlying `random.Random` instance, see >>> # [Randomization](https://coolname.readthedocs.io/en/latest/randomization.html). ``` -------------------------------- ### Generate Deterministic Slug with pseudohash_slug Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/deterministic-pseudohash.md Generates a deterministic slug for a given input. Useful when the same input should always produce the same output without persistent storage. Note that duplicates can still occur. ```python from coolname_hash import pseudohash_slug print(pseudohash_slug(123)) print(pseudohash_slug('qwerty')) print(pseudohash_slug('\x00\x01\xFF')) ``` -------------------------------- ### JSON Configuration with max_length for phrases Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md This JSON configuration defines a phrase list with a maximum character length of 6 for each phrase. Spaces are not counted towards the length limit. ```json { "all": { "type": "phrases", "phrases": ["big cat"], "max_length": 6 } } ``` -------------------------------- ### Custom Name Generator Configuration Source: https://github.com/alexanderlukanin13/coolname/blob/master/README.rst Defines and uses a custom name generator with specific word lists for first and last names. ```python >>> from coolname import RandomGenerator >>> generator = RandomGenerator({ ... 'all': { ... 'type': 'cartesian', ... 'lists': ['first_name', 'last_name'] ... }, ... 'first_name': { ... 'type': 'words', ... 'words': ['james', 'john'] ... }, ... 'last_name': { ... 'type': 'words', ... 'words': ['smith', 'brown'] ... } ... }) >>> generator.generate_slug() 'james-brown' ``` -------------------------------- ### Generate Multiple Slugs with Custom Separator and Length Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/index.md Command-line usage to generate multiple slugs (2) with a specified length (3) and separator ('_'). ```bash $ coolname 3 -n 2 -s '_' "wildebeest_of_original_champagne" "ara_of_imminent_luck" ``` -------------------------------- ### JSON Configuration with number_of_words constraint Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md This JSON configuration enforces that each phrase in the list must contain exactly 2 words. Phrases with a different word count will cause an error during generator initialization. ```json { "all": { "type": "phrases", "phrases": [ "washing machine", "microwave oven", "vacuum cleaner", "large hadron collider" ], "number_of_words": 2 } } ``` -------------------------------- ### Generate Slug with 2 Words Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/index.md Generate a slug specifically composed of two words. ```python >>> generate_slug(2) 'mottled-crab' ``` -------------------------------- ### JSON Configuration with max_slug_length Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/customization.md This JSON configuration sets a maximum slug length of 11. Combinations exceeding this length will be silently discarded during generation. ```json { "adjective": { "type": "words", "words": ["red", "blue", "green"] }, "noun": { "type": "words", "words": ["line", "square", "circle"] }, "all": { "type": "cartesian", "lists": ["adjective", "noun"], "max_slug_length": 11 } } ``` -------------------------------- ### Generate Random Name as List Source: https://github.com/alexanderlukanin13/coolname/blob/master/README.rst Generates a random name as a list of words. Useful for custom formatting. ```python >>> from coolname import generate >>> generate() ['beneficial', 'bronze', 'bee', 'of', 'glee'] ``` -------------------------------- ### Generate Random Slug (Features Section) Source: https://github.com/alexanderlukanin13/coolname/blob/master/README.rst Generates a random slug, as demonstrated in the features section. ```python >>> from coolname import generate_slug >>> generate_slug() 'qualified-agama-of-absolute-kindness' ``` -------------------------------- ### Exporting Environment Variables (Bash) Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/environment-variables.md Set environment variables in bash to specify a custom data directory or module for the Coolname generator. ```bash export COOLNAME_DATA_DIR=some/path export COOLNAME_DATA_MODULE=some.module ``` -------------------------------- ### Generate Slug with 3 Words Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/index.md Generate a slug specifically composed of three words. ```python >>> generate_slug(3) 'fantastic-acoustic-whale' ``` -------------------------------- ### Generate Slug with 4 Words Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/index.md Generate a slug specifically composed of four words. ```python >>> generate_slug(4) 'military-diamond-tuatara-of-endeavor' ``` -------------------------------- ### Custom generator configuration with word_regex (5.0.0) Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/history.md The definition of a valid word in custom generators is now controlled by the word_regex parameter, which defaults to '\w+'. ```python >>> # What is considered a valid word? It’s now controlled by word_regex parameter, \w+ by default. ``` -------------------------------- ### Replace Random Generator for Instances Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/randomization.md To use a custom random number generator for a specific `RandomGenerator` instance, pass a `random.Random` object initialized with a seed to the constructor. This allows for isolated control over randomness for that instance. ```python from coolname import RandomGenerator import random, os seed = os.urandom(128) generator = RandomGenerator(config, random=random.Random(seed)) ``` -------------------------------- ### Configuring custom generators with ensure_unique (5.0.0) Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/history.md In custom generators, the default parameter value for ensure_unique has changed to True. This ensures sequences are generated without repeating words by default. ```python >>> # Custom generators can forget about ensure_unique and still generate sequences without repeating words. >>> # Consider also using ensure_unique_prefix (disabled by default). ``` -------------------------------- ### Generate Slug with Specific Length Source: https://github.com/alexanderlukanin13/coolname/blob/master/README.rst Generates slugs with a specified number of words (2, 3, or 4). ```python >>> generate_slug(2) 'mottled-crab' >>> generate_slug(3) 'fantastic-acoustic-whale' >>> generate_slug(4) 'military-diamond-tuatara-of-endeavor' ``` -------------------------------- ### Include Coolname Data Module with PyInstaller Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/pyinstaller.md Use the --hidden-import flag to explicitly specify the coolname data module when building an executable with PyInstaller. This prevents a ModuleNotFoundError at runtime. ```bash pyinstaller myscript.py --hidden-import coolname.data ``` -------------------------------- ### Changing default generator with environment variables (1.0.4) Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/history.md The default generator can be changed using the COOLNAME_DATA_DIR and COOLNAME_DATA_MODULE environment variables, which also helps in saving memory. ```python >>> # Change the default generator using `COOLNAME_DATA_DIR` and `COOLNAME_DATA_MODULE`. This also saves memory! ``` -------------------------------- ### Generate Random Slug Source: https://github.com/alexanderlukanin13/coolname/blob/master/README.rst Generates a random human-readable slug. Multiple calls produce different results. ```python >>> from coolname import generate_slug >>> generate_slug() 'tiny-optimal-crocodile-of-progress' >>> generate_slug() 'cherubic-leopard-of-delightful-serendipity' >>> generate_slug() 'wealthy-athletic-swift-of-tempest' ``` -------------------------------- ### PyInstaller Runtime Error: ModuleNotFoundError Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/pyinstaller.md This traceback illustrates the error that occurs if the coolname.data module is not correctly included when building a PyInstaller executable. Ensure the module is specified during the build process. ```bash Traceback (most recent call last): File "myscript.py", line 1, in from coolname import generate_slug File "pyimod02_importers.py", line 457, in exec_module File "coolname/__init__.py", line 7, in File "pyimod02_importers.py", line 457, in exec_module File "coolname/impl.py", line 639, in File "coolname/impl.py", line 631, in _create_default_generator File "importlib/__init__.py", line 88, in import_module ModuleNotFoundError: No module named 'coolname.data' [PYI-12311:ERROR] Failed to execute script 'myscript' due to unhandled exception! ``` -------------------------------- ### Re-seed Default Random Generator Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/randomization.md To re-seed the default random number generator used by Coolname, call `random.seed()` with a source of randomness. This ensures that subsequent random operations are based on the new seed. ```python import os, random random.seed(os.urandom(128)) ``` -------------------------------- ### Renaming RandomNameGenerator to RandomGenerator (1.0.4) Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/history.md In version 1.0.4, the class RandomNameGenerator was renamed to RandomGenerator. The randomize() method was also removed as it was an alias for random.seed(). ```python >>> # Renamed `RandomNameGenerator` to `RandomGenerator`. >>> # `randomize()` was removed, because it was just an alias to `random.seed()`. ``` -------------------------------- ### Replace Random Generator Globally Source: https://github.com/alexanderlukanin13/coolname/blob/master/docs/randomization.md To replace the random number generator used by global functions like `coolname.generate()` and `coolname.generate_slug()`, use the `coolname.replace_random()` function. This affects all subsequent global calls to these functions. ```python import coolname import random, os seed = os.urandom(128) coolname.replace_random(random.Random(seed)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.