All Projects → paul-wolf → strgen

paul-wolf / strgen

Licence: BSD-3-Clause license
A Python module for a template language that generates randomized data

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to strgen

grand
Grand is a Go random string generator
Stars: ✭ 12 (-64.71%)
Mutual labels:  random, random-string, string-generator
jRand
A Java library to generate random data for all sorts of things. Java random data faker
Stars: ✭ 27 (-20.59%)
Mutual labels:  random, random-generation, random-string
Markovnamegenerator
✒️ Markov process-based procedural name and word generator
Stars: ✭ 300 (+782.35%)
Mutual labels:  random, random-generation
Rando.js
The world's easiest, most powerful random function.
Stars: ✭ 659 (+1838.24%)
Mutual labels:  random, random-generation
Easy Random
The simple, stupid random Java beans/records generator
Stars: ✭ 1,095 (+3120.59%)
Mutual labels:  random, random-generation
fastfaker
Fast, concurrent fake data generator for any structure or type.
Stars: ✭ 21 (-38.24%)
Mutual labels:  random, randomizer
SharpLoader
🔮 [C#] Source code randomizer and compiler
Stars: ✭ 36 (+5.88%)
Mutual labels:  random, randomizer
Random compat
PHP 5.x support for random_bytes() and random_int()
Stars: ✭ 7,950 (+23282.35%)
Mutual labels:  random, random-generation
relude-random
Composable random generators based on the PCG paper
Stars: ✭ 15 (-55.88%)
Mutual labels:  random, random-generation
Generatedata
A powerful, feature-rich, random test data generator.
Stars: ✭ 1,883 (+5438.24%)
Mutual labels:  random, random-generation
RandomGenKt
Kotlin port of RandomGen
Stars: ✭ 28 (-17.65%)
Mutual labels:  random, random-generation
REGularEXpressions
All you need to know about Regular Expressions collected at a place !
Stars: ✭ 44 (+29.41%)
Mutual labels:  regular-expression, character-set
Mir Random
Advanced Random Number Generators
Stars: ✭ 30 (-11.76%)
Mutual labels:  random, random-generation
Randomkit
Random data generation in Swift
Stars: ✭ 1,458 (+4188.24%)
Mutual labels:  random, random-generation
awesome-randomizers
🎲 A curated list of awesome services for obtaining random results.
Stars: ✭ 36 (+5.88%)
Mutual labels:  random, randomizer
datagen
Java lib that generates random data (numbers, strings, dates) - mostly to facilitate Randomized Testing.
Stars: ✭ 56 (+64.71%)
Mutual labels:  random, random-generation
golden-colors
Generate random colors using Golden ratio conjugate
Stars: ✭ 16 (-52.94%)
Mutual labels:  random
irrec
composable regular expressions based on Kleene algebras and recursion schemes
Stars: ✭ 14 (-58.82%)
Mutual labels:  regular-expression
flutter fortune wheel
Visualize random selections with Flutter widgets like the wheel of fortune.
Stars: ✭ 60 (+76.47%)
Mutual labels:  random
RandLib
🚀 A library designed to facilitate work with probability, statistics and stochastic calculus
Stars: ✭ 64 (+88.24%)
Mutual labels:  random

strgen

Python package Documentation Status

PyPI - Python Version

PyPi Version

Generate test data, unique ids, passwords, vouchers or other randomized textual data very quickly using a template language. The template language is superficially similar to regular expressions but instead of defining how to match or capture strings, it defines how to generate randomized strings. A very simple invocation to produce a random string with word characters of 30 characters length:

from strgen import StringGenerator as SG
SG(r"[\w]{30}").render()
'wQjLVRIj1sjjslORpqLJyDObaCnDR2'

Full documentation

The current package requires Python 3.6 or higher. Use version 0.3.4 or earlier if you want to use Python 2.7 or an earlier Python 3 version.

NB: with version 0.4.2, the preferred method for generating a unique list is StringGenerator.render_set() instead of render_list(). Generate 50000 unique secure tokens in a few seconds:

secure_tokens = SG("[\p\w]{32}").render_set(50000)

render_set() does not support a progress callback.

There is a rich feature set to randomize strings in situ or include external data.

The purpose of this module is to save the Python developer from having to write verbose code around the same pattern every time to generate passwords, keys, tokens, test data, etc. of this sort:

my_secret_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(30))

that is:

  1. Hard to read even at this simplistic level.
  2. Hard to safely change quickly. Even modest additions to the requirements need unreasonably verbose solutions.
  3. Doesn’t use safe encryption standards.
  4. Doesn’t provide the implied minimal guarantees of character occurance.
  5. Hard to track back to requirements (“must be between x and y in length and have characters from sets Q, R and S”).

The template uses short forms similar to those of regular expressions. An example template for generating a strong password:

[\w\p]{20}

will generate something like the following:

P{:45Ec5$3)2!I68x`{6

Guarantee at least two “special” characters in a string:

[\w\p]{10}&[\p]{2}

You can also generate useful test data, like fake emails with plenty of variation:

[\c]{10}.[\c]{5:10}@[\c]{3:12}.(com|net|org)

Requirements

From version 0.4.0, support for Python 2 is dropped. If you still need support for Python 2, use version 0.3.4.

There are no dependencies beyond the Python Standard Library.

Installation

Install as standard for Python packages from PyPi:

pip install StringGenerator

License

Released under the BSD license.

Acknowledgements

Thanks to Robert LeBlanc who caught some important errors in escaping special characters. Thanks to Andreas Motl for the progress counter.

Original Author: [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].