Generate random strings from regular expression patterns.
string-gen takes a regex pattern and produces random strings that match it. Common use cases include:
- Test data generation — create realistic inputs for unit and integration tests
- Fixtures — produce parameterized test fixtures on the fly
- Fuzzing — generate semi-structured random inputs for fuzz testing
- Mock data — build placeholder data for prototyping and demos
Documentation | API Reference | Cookbook
pip install string-genfrom string_gen import StringGen
# Basic generation
gen = StringGen(r'(A|B)\d{4}(\.|-)\d{1}')
gen.render() # e.g. 'B9954.4'
# List of strings
gen = StringGen(r'[A-Z]{3}-\d{3}')
gen.render_list(5) # e.g. ['XKR-839', 'BNQ-271', 'JYL-054', 'WMT-692', 'AFZ-418']
# Built-in patterns
from string_gen.patterns import UUID4, IPV4
StringGen(UUID4).render() # e.g. '52aabe4b-01fa-4b33-8976-b53b09f49e72'
StringGen(IPV4).render() # e.g. '192.168.1.42'
# Custom alphabets
from string_gen.alphabets import CYRILLIC
StringGen(r'\w{10}', alphabet=CYRILLIC).render() # e.g. 'ёЩкРблнЫйМ'For full documentation visit tolstislon.github.io/string-gen.
Contributions are very welcome. You might want to:
- Fix spelling errors
- Improve documentation
- Add tests for untested code
- Add new features
- Fix bugs
- Python 3.8+
- uv
- Clone the repository
git clone https://github.com/tolstislon/string-gen.git cd string-gen - Install dev dependencies
uv sync
- Run ruff format
uv run ruff format
- Run ruff check
uv run ruff check --fix
- Run tests
uv run pytest tests/