A Python library for generating realistic random names, usernames, and placeholder data for testing purposes.
Project description
randname
A lightweight, dependency-free Python library for generating realistic random names, usernames, and placeholder data for testing purposes.
โจ Features
- ๐ฏ Zero dependencies - Uses only Python standard library
- ๐ Realistic names - Curated datasets of real first and last names
- ๐ค Gender support - Male, female, unisex, or random name generation
- ๐ฎ Username styles - Simple, professional, and gamer-style usernames
- ๐ค Type hints - Full type annotation support
- ๐ Well documented - Comprehensive docstrings and examples
๐ฆ Installation
pip install randname
Or install from source:
git clone https://github.com/yourusername/randname.git
cd randname
pip install -e .
๐ Quick Start
import randname
# Generate random names
print(randname.full_name()) # "Sarah Johnson"
print(randname.first_name()) # "Michael"
print(randname.last_name()) # "Williams"
# Generate with specific gender
print(randname.full_name(gender="male")) # "Robert Brown"
print(randname.full_name(gender="female")) # "Emily Garcia"
print(randname.full_name(gender="unisex")) # "Jordan Taylor"
# Generate usernames
print(randname.username()) # "michael_johnson23"
print(randname.username(style="professional")) # "m.smith"
print(randname.username(style="gamer")) # "ShadowHunter99"
# Generate username from a specific name
print(randname.username_from_name("Alice")) # "alice_martinez42"
print(randname.username_from_name("Bob", "Wilson")) # "bobwilson"
print(randname.username_from_name("Jane", style="professional")) # "j.doe"
๐ API Reference
Name Generation
first_name(gender="random")
Generate a random first name.
Parameters:
gender(str): One of"male","female","unisex", or"random"(default)
Returns: str - A randomly selected first name
randname.first_name() # Any gender
randname.first_name(gender="male") # Male name
randname.first_name(gender="female") # Female name
randname.first_name(gender="unisex") # Gender-neutral name
last_name()
Generate a random last name.
Returns: str - A randomly selected last name
randname.last_name() # "Johnson"
full_name(gender="random")
Generate a random full name (first + last).
Parameters:
gender(str): One of"male","female","unisex", or"random"(default)
Returns: str - A full name in "FirstName LastName" format
randname.full_name() # "Emma Wilson"
randname.full_name(gender="male") # "James Anderson"
get_available_genders()
Get a list of all available gender options.
Returns: list[str] - ["male", "female", "unisex", "random"]
Username Generation
username(style="simple", add_numbers=True)
Generate a random username.
Parameters:
style(str): One of"simple","professional", or"gamer"(default:"simple")add_numbers(bool): Whether to append random numbers (default:True)
Returns: str - A randomly generated username
randname.username() # "johnsmith42"
randname.username(style="simple") # "sarah_jones87"
randname.username(style="professional") # "j.williams"
randname.username(style="gamer") # "NightPhoenix99"
randname.username(style="gamer", add_numbers=False) # "ShadowHunter"
username_from_name(fname, lname=None, style="simple", add_numbers=True)
Generate a username from a provided name.
Parameters:
fname(str): First name to base the username onlname(str, optional): Last name (random if not provided)style(str): Username style (default:"simple")add_numbers(bool): Whether to append random numbers (default:True)
Returns: str - A username based on the provided name
randname.username_from_name("Alice") # "alicesmith23"
randname.username_from_name("Bob", "Wilson") # "bob_wilson"
randname.username_from_name("Jane", style="professional") # "j.doe"
get_available_styles()
Get a list of all available username styles.
Returns: list[str] - ["simple", "professional", "gamer"]
Utility Functions
random_digits(length=4)
Generate a string of random digits.
randname.random_digits(4) # "8472"
randname.random_digits(6) # "123456"
slugify(text, separator="")
Convert a string to a URL/username-safe slug.
randname.slugify("John Doe") # "johndoe"
randname.slugify("Mary Jane", "_") # "mary_jane"
randname.slugify("O'Brien") # "obrien"
capitalize_words(text)
Capitalize the first letter of each word.
randname.capitalize_words("john doe") # "John Doe"
๐จ Username Styles Explained
| Style | Description | Examples |
|---|---|---|
simple |
Lowercase, basic formats | johnsmith, john_doe42, jsmith |
professional |
Clean, work-appropriate | john.smith, j.doe, smith.j |
gamer |
Cool prefixes/suffixes | ShadowHunter99, NightPhoenix, xDragonx |
๐งช Running Tests
# Run with unittest
python -m pytest tests/ -v
# Or directly
python tests/test_basic.py
๐ Project Structure
randname/
โโโ randname/ # Main package
โ โโโ __init__.py # Public API
โ โโโ names.py # Name generation logic
โ โโโ usernames.py # Username generation logic
โ โโโ utils.py # Helper utilities
โโโ tests/ # Unit tests
โ โโโ test_basic.py
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ pyproject.toml # Package configuration
โโโ .gitignore
๐ง Development
# Clone the repository
git clone https://github.com/yourusername/randname.git
cd randname
# Install in development mode
pip install -e .
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
๐ Extending the Name Dataset
You can easily extend the name datasets by importing and modifying the lists:
from randname.names import MALE_FIRST_NAMES, FEMALE_FIRST_NAMES, LAST_NAMES
# Add custom names
MALE_FIRST_NAMES.extend(["Krishna", "Arjun", "Rahul"])
FEMALE_FIRST_NAMES.extend(["Priya", "Ananya", "Sneha"])
LAST_NAMES.extend(["Patel", "Sharma", "Kumar"])
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Inspired by the need for simple, dependency-free test data generation
- Name datasets curated from common names across various cultures
Made with โค๏ธ for developers who need quick, realistic test data.
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 randnamepy-1.0.1.tar.gz.
File metadata
- Download URL: randnamepy-1.0.1.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf693377472a5539e232eab159b21d09fce7050b07a13f7f68605a770d626acb
|
|
| MD5 |
916d73ad297643b23b06ad9c44eafbcc
|
|
| BLAKE2b-256 |
5702254c2f1650e854f825b159df994d029681000673b2980ecd5eb3dc805104
|
File details
Details for the file randnamepy-1.0.1-py3-none-any.whl.
File metadata
- Download URL: randnamepy-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee129deb28be6d66d55c9841dd976e4e6c5aa724ee303e4bd85ab8f5338121b5
|
|
| MD5 |
32d3f795d88373a35019f1d695838b49
|
|
| BLAKE2b-256 |
21a36da56775f8b5281c56b13426d212fdda6e4cd4eb0a81c111620c45210361
|