Registry / testing / rstr
library3.2.2pypypi✓ verified 26d ago

rstr is a Python helper module designed for easily generating random strings of various types. It is suitable for applications such as fuzz testing, generating dummy data, or creating random values based on regular expressions. The library is currently at version 3.2.2 and is actively maintained.

pip install rstr
INSTALL
IMPORT
SIG · RSTR
R
rstr
testingpythonv3.2.2
Install
1.5s avg
Import
15ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.014s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.016s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

rstr
import rstr
Rstr
from rstr import Rstr
xeger
from rstr import xeger

Demonstrates basic random string generation, fixed-length generation, regex-based generation with `xeger`, and how to use a cryptographically secure random number generator.

import rstr from rstr import Rstr, xeger from random import SystemRandom # Generate a random string from a custom alphabet print(f"Random string from 'ABC': {rstr.rstr('ABC')}") # Generate a fixed-length random string print(f"4-char string from '0123456789': {rstr.rstr('0123456789', 4)}") # Generate a random string matching a regex pattern print(f"Random string matching '[a-z]{{5,10}}': {xeger(r'[a-z]{5,10}')}") # Use a cryptographically secure random source for sensitive cases cs_rstr = Rstr(SystemRandom()) print(f"Secure random string (16 hex chars): {cs_rstr.rstr('0123456789abcdef', 16)}")
Debug
Known issues
gotchaBy default, `rstr` uses Python's `random` module (Mersenne Twister), which is a pseudorandom number generator and is NOT cryptographically secure. Do not use default `rstr` for generating sensitive data like passwords or security tokens.
fix
For sensitive applications, initialize `Rstr` with `random.SystemRandom()`: `from rstr import Rstr; from random import SystemRandom; secure_rstr = Rstr(SystemRandom())`.
affects: All versions
gotchaThe `xeger()` function, which generates strings from regular expressions, can be very slow for complex or ambiguous regex patterns, as it may take a long time to find matching strings.
fix
Simplify regex patterns where possible, or consider using `star_plus_limit` argument of `Xeger` class to control repetition bounds more strictly for performance-critical scenarios. Profile performance with your specific patterns..
affects: All versions
gotchaWhen using `xeger()`, the `*` (zero or more) and `+` (one or more) metacharacters are not truly infinite. They have an arbitrary upper bound of 100 repetitions by default, which might not match expectations for very long strings. The maximum possible is 65535.
fix
You can explicitly set the `star_plus_limit` when creating an `Xeger` instance to change this upper bound: `xeger_instance = Xeger(star_plus_limit=200); xeger_instance.xeger(r'a*')`..
affects: All versions
breakingVersion 3.0.0 of `rstr` dropped support for Python 2.x. Attempts to use versions 3.x on Python 2.x environments will result in import errors or other incompatibilities.
fix
Ensure your project runs on Python 3.7 or newer. If Python 2.x compatibility is required, you must use an older `rstr` version (e.g., <3.0.0), which is not recommended due to lack of maintenance..
affects: >=3.0.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'rstr'
The 'rstr' package is not installed in the current Python environment or is not accessible via the PYTHONPATH.
fix
Install the library using pip: `pip install rstr`
TypeError: rstr() missing 1 required positional argument: 'pattern'
The `rstr.rstr()` function was called without providing the mandatory 'pattern' argument.
fix
Provide a string value for the 'pattern' argument, for example: `rstr.rstr('abc')` or `rstr.rstr('hello', 5)`.
AttributeError: module 'rstr' has no attribute 'random_string'
You attempted to call a non-existent or incorrectly named function on the `rstr` module.
fix
Use the correct function names provided by the library, such as `rstr.rstr()` for random strings or `rstr.xeger()` for regex-based generation.
re.error: missing ')' at position 0
The regular expression string passed to `rstr.xeger()` contains a syntax error, which is caught by Python's `re` module.
fix
Correct the syntax of the regular expression pattern, for example, ensure all parentheses are matched or character ranges are valid. Example: `rstr.xeger('[a-z]{3}')`
Upgrade
Version history
3.2.2latest on PyPI · released Oct 11, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources