Essential Generators
raw JSON → 1.0 verified Fri May 01 auth: no python
Generate fake data for application testing based on simple but flexible templates. Version 1.0 is stable but rarely updated. Templates support inline expressions, custom functions, and nested structures. Suitable for tests, prototypes, and data fixtures.
pip install essential-generators Common errors
error ImportError: No module named essential_generators ↓
cause The package name uses a hyphen while the module uses an underscore. Some users install the package but then try to import with a hyphen.
fix
Import using underscore: 'from essential_generators import DocumentGenerator'
error AttributeError: 'DocumentGenerator' object has no attribute 'gen_document' ↓
cause The user created the generator with an invalid parameter (e.g., 'path' instead of 'template_dir') or the generator failed to initialize correctly.
fix
Initialize with no arguments: gen = DocumentGenerator(). If you need a custom template directory, use gen = DocumentGenerator(template_dir='path').
Warnings
gotcha Templates use double-brace syntax like {{name.first_name}} but the library also supports shorthand placeholders like {{first_name}}. Mixing both can cause unexpected failures if the shorthand isn't defined. ↓
fix Stick to one style. Use {{name.first_name}} (full path) for consistency.
gotcha The library does not support nested template definitions inside lists; each element in a template list must be a primitive or a dict. Attempting to nest templates silently produces incorrect output. ↓
fix Avoid nesting templates inside arrays. Use the CyclicGenerator for repeating patterns instead.
deprecated The 'gen_document' method with positional arguments (e.g., gen_document(template, count)) is deprecated. Use keyword arguments or call gen_documents() for multiple outputs. ↓
fix Use gen.gen_document(template=my_template) or gen.gen_documents(5).
Imports
- DocumentGenerator wrong
import essential_generators DocumentGenerator()correctfrom essential_generators import DocumentGenerator - MarkovTextGenerator
from essential_generators import MarkovTextGenerator - CyclicGenerator
from essential_generators import CyclicGenerator
Quickstart
from essential_generators import DocumentGenerator
gen = DocumentGenerator()
doc = gen.gen_document()
print(doc)
# Generate a custom document from a template
template = {
'name': '{{name.first_name}} {{name.last_name}}',
'email': '{{email}}',
'address': '{{address.street}}, {{address.city}}'
}
custom = gen.gen_document(template)
print(custom)
# Generate multiple documents quickly
docs = gen.gen_documents(5)
for d in docs:
print(d)