Skip to main content

String gen

PyPI Downloads PyPI - Python Version PyPI - Implementation

Tests Ruff

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

Installation

Requires Python 3.10 or newer.

pip install string-gen

Quick Start

from 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.

Changelog

Contributing

Contributions are very welcome. You might want to:

  • Fix spelling errors
  • Improve documentation
  • Add tests for untested code
  • Add new features
  • Fix bugs

Getting started

  • Python 3.10+
  • uv
  1. Clone the repository
    git clone https://github.com/tolstislon/string-gen.git
    cd string-gen
    
  2. Install dev dependencies
    uv sync
    
  3. Run ruff format
    uv run ruff format
    
  4. Run ruff check
    uv run ruff check --fix
    
  5. Run tests
    uv run pytest tests/
    

Metadata

Release files for string-gen 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for string-gen 1.1.0
File Size Uploaded Provenance Actions
string_gen-1.1.0.tar.gz 37.3 kB Without provenance Details for string_gen-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for string-gen 1.1.0
File Interpreter ABI Platform Actions
string_gen-1.1.0-py3-none-any.whl Python 3 none any Details for string_gen-1.1.0-py3-none-any.whl

Total release size: 64.5 kB

Release files / string_gen-1.1.0.tar.gz

Download URL string_gen-1.1.0.tar.gz
Size 37.3 kB
Tags Source
SHA-256 checksum
How to use checksums
eae2a84b2addc0ac5a66fd5657ef813c5f6a98bbab510ad2377409673c24657a
BLAKE2b-256 checksum
How to use checksums
0bd823da5a4e30977ec8dd83a916a79c50dc2390ce384d33289f4095d78c7806
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / string_gen-1.1.0-py3-none-any.whl

Download URL string_gen-1.1.0-py3-none-any.whl
Size 27.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42d2a429bd7104a054d19dc6b84c64e03bc1dc7bd91b64897d81ae6a7e980cc6
BLAKE2b-256 checksum
How to use checksums
55ca3339e79f9a8f0b95601bd00f615ca0b946237ad8de1da3820efd7579c400
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for string-gen 1.1.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page