rstr
Generate random strings in Python
What it is and what it does
rstr is a lightweight utility for generating random strings in Python, useful for test data, fuzzing, and validation scenarios. It offers both low-level control—specifying custom alphabets and length ranges—and convenience methods for common character sets like digits, letters, URLs, and domain names. It can also generate strings matching regular expression patterns via its xeger() method.
The package has no external dependencies and runs on Python 3.7 through 3.11. However, it uses Python's standard random module by default, which is not cryptographically secure; for password generation or other security-sensitive applications, you must explicitly configure it to use SystemRandom(). Maintenance is aging, with the last release in October 2023 and no recent commits, though the codebase remains stable and production-ready.
Use it for:
- Generate test fixtures and dummy data for unit tests without external dependencies.
- Create fuzz-testing payloads with controlled character sets to probe input validation.
- Build random email addresses, URLs, or domain names matching specific format constraints.
- Generate random strings matching a regex pattern for testing regex-based parsers or validators.
- Produce test data for postal addresses or other domain-specific formats with predefined alphabets.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates random strings from custom alphabets, predefined character sets, or regular expressions for testing and dummy data creation.
Yes, if you need lightweight random string generation for testing or dummy data without external dependencies. The aging maintenance status is not a blocker for stable use, but verify compatibility with your Python version. Avoid for cryptographic applications unless you explicitly configure SystemRandom().
Install
rstr on PyPI
pip
pip install rstruv
uv add rstrpoetry
poetry add rstrInstalling rstr
Before you install
Low friction: pure Python with no external dependencies, distributed as a wheel. Maintenance is aging—last release was 2023-10-11 and the repository shows no recent activity, though it remains archived=false and supports current Python versions.
License in practice
Permissive BSD license places no restrictions on use, modification, or distribution in commercial or proprietary contexts.
Quickstart
pip install rstr
import rstr
# Generate random string from custom alphabet
rstr.rstr('ABC', 5, 10)
# Generate from predefined set
rstr.digits()
# Generate from regex pattern
rstr.xeger(r'[A-Z]\d[A-Z]')
For cryptographic use (passwords, tokens), you must instantiate with SystemRandom(); default random module is not cryptographically secure.
Verify before relying
- Whether xeger() supports all modern Python regex features or has known limitations beyond those mentioned.
- Likelihood of future updates for Python versions beyond 3.11.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 1,038 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,294,521/month — #2,669 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: rstr-3.2.2-py3-none-any.whl
Keywords: random string, reverse regex, reverse regular expression, testing, fuzz testing
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
exrexExrex generates all or random strings matching…
agpl · top 15,000 on PyPI
inventree-ipn-generatorAutomatically generates and assigns Internal…
permissive · top 15,000 on PyPI
random-password-generatorGenerates random passwords with configurable…
permissive · top 15,000 on PyPI
xkcdpassGenerates strong, memorable passphrases by…
permissive · top 15,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
random-addressGenerates random real US addresses with…
permissive · top 15,000 on PyPI
wonderwordsGenerates random English words and sentences…
permissive · top 15,000 on PyPI
boofuzzBoofuzz is a network protocol fuzzing framework…
copyleft · top 15,000 on PyPI
iregexp-checkValidates regular expressions against RFC 9485…
permissive · top 15,000 on PyPI
petnameGenerates random, pronounceable names by…
permissive · top 15,000 on PyPI