API

eadred comes with some helper functions for generating random data. If they work for you, yay! If not, you can look at the code and write your own.

eadred.helpers.make_unique(gen)

Wraps a generator to uniquify strings by appending counter

Parameters:gen – the generator to wrap

Example:

from eadred.helpers import name_generator, make_unique

gen = make_unique(name_generator())
for i in range(50):
    mymodel = SomeModel(name=gen.next())
    mymodel.save()

Example 2:

>>> gen = make_unique(name_generator(['alice', 'jane', 'harry']))
>>> gen.next()
u'alice0'
>>> gen.next()
u'harry1'
>>> gen.next()
u'jane2'
eadred.helpers.name_generator(names=None)

Creates a generator for generating names.

Parameters:names – list or tuple of names you want to use; defaults to ENGLISH_MONARCHS
Returns:generator for names

Example:

from eadred.helpers import name_generator

gen = name_generator()
for i in range(50):
    mymodel = SomeModel(name=gen.next())
    mymodel.save()

Example 2:

>>> gen = name_generator()
>>> gen.next()
u'James II'
>>> gen.next()
u'Stephen of Blois'
>>> gen.next()
u'James I'

Note

This gives full names for a “name” field. It’s probably not useful for broken down name fields like “firstname”, “lastname”, etc.

eadred.helpers.email_generator(names=None, domains=None, unique=False)

Creates a generator for generating email addresses.

Parameters:
  • names – list of names to use; defaults to ENGLISH_MONARCHS lowercased, ascii-fied, and stripped of whitespace
  • domains – list of domains to use; defaults to DOMAINS
  • unique – True if you want the username part of the email addresses to be unique
Returns:

generator

Example:

from eadred.helpers import email_generator

gen = email_generator()
for i in range(50):
    mymodel = SomeModel(email=gen.next())
    mymodel.save()

Example 2:

>>> gen = email_generator()
>>> gen.next()
'eadwig@example.net'
>>> gen.next()
'henrybeauclerc@mail1.example.org'
>>> gen.next()
'williamrufus@example.com'
eadred.helpers.sentence_generator(sentences=None)

Creates a generator for generating sentences.

Parameters:sentences – list or tuple of sentences you want to use; defaults to LOREM
Returns:generator

Example:

from eadred.helpers import sentence_generator

gen = sentence_generator()
for i in range(50):
    mymodel = SomeModel(summary=gen.next())
    mymodel.save()
eadred.helpers.paragraph_generator(sentences=None)

Creates a generator for generating paragraphs.

Parameters:sentences – list or tuple of sentences you want to use; defaults to LOREM
Returns:generator

Example:

from eadred.helpers import paragraph_generator

gen = paragraph_generator()
for i in range(50):
    mymodel = SomeModel(description=gen.next())
    mymodel.save()