Pythonic Lorem Ipsum Generator¶
Lorem Ipsum Generator¶
Get Random Words¶
- lorem.word(pool=('ad', 'adipiscing', 'aliqua', 'aliquip', 'amet', 'anim', 'aute', 'cillum', 'commodo', 'consectetur', 'consequat', 'culpa', 'cupidatat', 'deserunt', 'do', 'dolor', 'dolore', 'duis', 'ea', 'eiusmod', 'elit', 'enim', 'esse', 'est', 'et', 'eu', 'ex', 'excepteur', 'exercitation', 'fugiat', 'id', 'in', 'incididunt', 'ipsum', 'irure', 'labore', 'laboris', 'laborum', 'lorem', 'magna', 'minim', 'mollit', 'nisi', 'non', 'nostrud', 'nulla', 'occaecat', 'officia', 'pariatur', 'proident', 'qui', 'quis', 'reprehenderit', 'sed', 'sint', 'sit', 'sunt', 'tempor', 'ullamco', 'ut', 'velit', 'veniam', 'voluptate'), count=1, func=None, args=(), kwargs={})[source]¶
Generate a list of random words.
>>> list(itertools.cycle(word(count=3), 3)) ['labore', 'tempor', 'commodo'] >>> list(itertools.cycle(word(count=3, func='capitalize'), 3)) ['Ea', 'Lorem', 'Do'] >>> list(itertools.cycle(word(count=3, func=lambda s: s.upper()), 3)) ['UT', 'AMET', 'EXCEPTEUR']
- Parameters
pool (Iterable[str]) – List of words to be used as random word pool.
count (int) – Number of non-repeated random words.
func (Optional[str | Callable[[str], str]]) – Filter function. It can be an attribute name of
str
, or a customised function that takes the originalstr
and returns the modifiedstr
.args (tuple[str, ...]) – Additional positional arguments for
func
.kwargs (dict[str, Any]) – Additional keyword arguments for
func
.
- Returns
Indefinite random words generator.
- Return type
Iterator[str]
- lorem.get_word(pool=('ad', 'adipiscing', 'aliqua', 'aliquip', 'amet', 'anim', 'aute', 'cillum', 'commodo', 'consectetur', 'consequat', 'culpa', 'cupidatat', 'deserunt', 'do', 'dolor', 'dolore', 'duis', 'ea', 'eiusmod', 'elit', 'enim', 'esse', 'est', 'et', 'eu', 'ex', 'excepteur', 'exercitation', 'fugiat', 'id', 'in', 'incididunt', 'ipsum', 'irure', 'labore', 'laboris', 'laborum', 'lorem', 'magna', 'minim', 'mollit', 'nisi', 'non', 'nostrud', 'nulla', 'occaecat', 'officia', 'pariatur', 'proident', 'qui', 'quis', 'reprehenderit', 'sed', 'sint', 'sit', 'sunt', 'tempor', 'ullamco', 'ut', 'velit', 'veniam', 'voluptate'), count=1, sep=' ', func=None, args=(), kwargs={})[source]¶
Return random words.
>>> get_word(count=3) 'anim voluptate non' >>> get_word(count=3, func='capitalize') 'Non Labore Ut' >>> get_word(count=3, func=lambda s: s.upper()) 'NISI TEMPOR CILLUM'
- Parameters
pool (Iterable[str]) – List of words to be used as random word pool.
count (int | tuple[int, int]) – Number of random words. To generate random number of words, supply a 2-element tuple of
int
, the function will userandom.randint()
to choose a random integer as the number of random words.sep (str) – Seperator between each word.
func (Optional[str | Callable[[str], str]]) – Filter function. It can be a function name of
str
, or a customised function that takes the originalstr
and returns the modifiedstr
.args (tuple[str, ...]) – Additional positional arguments for
func
.kwargs (dict[str, Any]) – Additional keyword arguments for
func
.
- Returns
Random words.
- Return type
Get Random Sentences¶
- lorem.sentence(pool=('ad', 'adipiscing', 'aliqua', 'aliquip', 'amet', 'anim', 'aute', 'cillum', 'commodo', 'consectetur', 'consequat', 'culpa', 'cupidatat', 'deserunt', 'do', 'dolor', 'dolore', 'duis', 'ea', 'eiusmod', 'elit', 'enim', 'esse', 'est', 'et', 'eu', 'ex', 'excepteur', 'exercitation', 'fugiat', 'id', 'in', 'incididunt', 'ipsum', 'irure', 'labore', 'laboris', 'laborum', 'lorem', 'magna', 'minim', 'mollit', 'nisi', 'non', 'nostrud', 'nulla', 'occaecat', 'officia', 'pariatur', 'proident', 'qui', 'quis', 'reprehenderit', 'sed', 'sint', 'sit', 'sunt', 'tempor', 'ullamco', 'ut', 'velit', 'veniam', 'voluptate'), count=1, comma=(0, 2), word_range=(4, 8))[source]¶
Generate a list of random sentences.
>>> list(itertools.islice(sentence(), 1)) ['Aute irure et commodo sunt do duis dolor.']
- Parameters
pool (Iterable[str]) – List of words to be used as random word pool.
count (int) – Number of non-repeated random sentences.
comma (tuple[int, int]) – Random range for number of commas. The function will use
random.randint()
to choose a random integer as the number of commas.word_range (tuple[int, int]) – Random range for number of words in each sentence. The function will use
random.randint()
to choose a random integer as the number of words.
- Returns
Indefinite random sentence generator.
- Return type
Iterator[str]
- lorem.get_sentence(pool=('ad', 'adipiscing', 'aliqua', 'aliquip', 'amet', 'anim', 'aute', 'cillum', 'commodo', 'consectetur', 'consequat', 'culpa', 'cupidatat', 'deserunt', 'do', 'dolor', 'dolore', 'duis', 'ea', 'eiusmod', 'elit', 'enim', 'esse', 'est', 'et', 'eu', 'ex', 'excepteur', 'exercitation', 'fugiat', 'id', 'in', 'incididunt', 'ipsum', 'irure', 'labore', 'laboris', 'laborum', 'lorem', 'magna', 'minim', 'mollit', 'nisi', 'non', 'nostrud', 'nulla', 'occaecat', 'officia', 'pariatur', 'proident', 'qui', 'quis', 'reprehenderit', 'sed', 'sint', 'sit', 'sunt', 'tempor', 'ullamco', 'ut', 'velit', 'veniam', 'voluptate'), count=1, sep=' ', comma=(0, 2), word_range=(4, 8))[source]¶
Return random sentences.
>>> get_sentence() 'Nostrud laboris lorem minim sit culpa, aliqua nostrud in amet, sint pariatur eiusmod esse.'
- Parameters
pool (Iterable[str]) – List of words to be used as random word pool.
count (int | tuple[int, int]) – Number of random sentences. To generate random number of sentences, supply a 2-element tuple of
int
, the function will userandom.randint()
to choose a random integer as the number of random sentences.sep (str) – Seperator between each sentence.
comma (tuple[int, int]) – Random range for number of commas. The function will use
random.randint()
to choose a random integer as the number of commas.word_range (tuple[int, int]) – Random range for number of words in each sentence. The function will use
random.randint()
to choose a random integer as the number of words.
- Returns
Random sentences.
- Return type
Get Random Paragraphs¶
- lorem.paragraph(pool=('ad', 'adipiscing', 'aliqua', 'aliquip', 'amet', 'anim', 'aute', 'cillum', 'commodo', 'consectetur', 'consequat', 'culpa', 'cupidatat', 'deserunt', 'do', 'dolor', 'dolore', 'duis', 'ea', 'eiusmod', 'elit', 'enim', 'esse', 'est', 'et', 'eu', 'ex', 'excepteur', 'exercitation', 'fugiat', 'id', 'in', 'incididunt', 'ipsum', 'irure', 'labore', 'laboris', 'laborum', 'lorem', 'magna', 'minim', 'mollit', 'nisi', 'non', 'nostrud', 'nulla', 'occaecat', 'officia', 'pariatur', 'proident', 'qui', 'quis', 'reprehenderit', 'sed', 'sint', 'sit', 'sunt', 'tempor', 'ullamco', 'ut', 'velit', 'veniam', 'voluptate'), count=1, comma=(0, 2), word_range=(4, 8), sentence_range=(5, 10))[source]¶
Generate a list of random paragraphs.
>>> list(itertools.islice(paragraph(), 1)) ['Aute sint et cupidatat aliquip. Non exercitation est aliquip voluptate ' 'fugiat, reprehenderit ad occaecat laboris velit consequat. Magna enim ' 'deserunt aute laborum fugiat exercitation. Aliqua ex sunt fugiat in ' 'magna voluptate. Elit nisi exercitation nostrud. Magna proident et ' 'fugiat eiusmod cupidatat fugiat, sit culpa fugiat non ea eu ' 'reprehenderit elit. Proident mollit mollit ut cillum. Nostrud voluptate ' 'aliquip cupidatat anim.']
- Parameters
pool (Iterable[str]) – List of words to be used as random word pool.
count (int) – Number of non-repeated random paragraphs.
comma (tuple[int, int]) – Random range for number of commas. The function will use
random.randint()
to choose a random integer as the number of commas.word_range (tuple[int, int]) – Random range for number of words in each sentence. The function will use
random.randint()
to choose a random integer as the number of words.sentence_range (tuple[int, int]) – Random range for number of sentences in each paragraph. The function will use
random.randint()
to choose a random integer as the number of sentences.
- Returns
Random paragraph generator.
- Return type
Iterator[str]
- lorem.get_paragraph(pool=('ad', 'adipiscing', 'aliqua', 'aliquip', 'amet', 'anim', 'aute', 'cillum', 'commodo', 'consectetur', 'consequat', 'culpa', 'cupidatat', 'deserunt', 'do', 'dolor', 'dolore', 'duis', 'ea', 'eiusmod', 'elit', 'enim', 'esse', 'est', 'et', 'eu', 'ex', 'excepteur', 'exercitation', 'fugiat', 'id', 'in', 'incididunt', 'ipsum', 'irure', 'labore', 'laboris', 'laborum', 'lorem', 'magna', 'minim', 'mollit', 'nisi', 'non', 'nostrud', 'nulla', 'occaecat', 'officia', 'pariatur', 'proident', 'qui', 'quis', 'reprehenderit', 'sed', 'sint', 'sit', 'sunt', 'tempor', 'ullamco', 'ut', 'velit', 'veniam', 'voluptate'), count=1, sep='\n', comma=(0, 2), word_range=(4, 8), sentence_range=(5, 10))[source]¶
Return random paragraphs.
>>> get_paragraph() 'Exercitation magna sunt excepteur irure adipiscing commodo duis. Est ' 'ipsum qui deserunt, deserunt nostrud reprehenderit esse. Do velit ' 'est in velit sed. Sunt officia officia lorem. Commodo lorem ' 'exercitation veniam officia pariatur velit. Deserunt deserunt sed ' 'consequat laborum consequat dolor. Et consectetur irure sint elit tempor,' ' est minim nisi eiusmod id excepteur. Minim cillum veniam sed aliquip ' 'anim sit, pariatur nostrud ex cillum laboris laborum. Laborum ullamco ' 'mollit elit. Amet id incididunt ipsum sed.'
- Parameters
pool (Iterable[str]) – List of words to be used as random word pool.
count (int | tuple[int, int]) – Number of random paragraphs. To generate random number of paragraphs, supply a 2-element tuple of
int
, the function will userandom.randint()
to choose a random integer as the number of random paragraphs.sep (str) – Seperator between each paragraph. The default value is OS-dependent as
os.linsep
(\r\n
on Windows,\n
on POSIX).comma (tuple[int, int]) – Random range for number of commas. The function will use
random.randint()
to choose a random integer as the number of commas.word_range (tuple[int, int]) – Random range for number of words in each sentence. The function will use
random.randint()
to choose a random integer as the number of words.sentence_range (tuple[int, int]) – Random range for number of sentences in each paragraph. The function will use
random.randint()
to choose a random integer as the number of sentences.
- Returns
Random paragraphs.
- Return type
Internal utilities¶
- lorem._TEXT = ('ad', 'adipiscing', 'aliqua', 'aliquip', 'amet', 'anim', 'aute', 'cillum', 'commodo', 'consectetur', 'consequat', 'culpa', 'cupidatat', 'deserunt', 'do', 'dolor', 'dolore', 'duis', 'ea', 'eiusmod', 'elit', 'enim', 'esse', 'est', 'et', 'eu', 'ex', 'excepteur', 'exercitation', 'fugiat', 'id', 'in', 'incididunt', 'ipsum', 'irure', 'labore', 'laboris', 'laborum', 'lorem', 'magna', 'minim', 'mollit', 'nisi', 'non', 'nostrud', 'nulla', 'occaecat', 'officia', 'pariatur', 'proident', 'qui', 'quis', 'reprehenderit', 'sed', 'sint', 'sit', 'sunt', 'tempor', 'ullamco', 'ut', 'velit', 'veniam', 'voluptate')¶
The original lorem ipsum text pool.
The text pool is generated directly from the original lorem ipsum paragraph:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- class lorem.LoremGenerator(pool=('ad', 'adipiscing', 'aliqua', 'aliquip', 'amet', 'anim', 'aute', 'cillum', 'commodo', 'consectetur', 'consequat', 'culpa', 'cupidatat', 'deserunt', 'do', 'dolor', 'dolore', 'duis', 'ea', 'eiusmod', 'elit', 'enim', 'esse', 'est', 'et', 'eu', 'ex', 'excepteur', 'exercitation', 'fugiat', 'id', 'in', 'incididunt', 'ipsum', 'irure', 'labore', 'laboris', 'laborum', 'lorem', 'magna', 'minim', 'mollit', 'nisi', 'non', 'nostrud', 'nulla', 'occaecat', 'officia', 'pariatur', 'proident', 'qui', 'quis', 'reprehenderit', 'sed', 'sint', 'sit', 'sunt', 'tempor', 'ullamco', 'ut', 'velit', 'veniam', 'voluptate'), dupe=1)[source]¶
Bases:
object
Generate random words.
- Parameters
- gen_word(func=None, args=(), kwargs={})[source]¶
Generate random word.
- Parameters
func (Optional[str | Callable[[str], str]]) – Filter function. It can be an attribute name of
str
, or a customised function that takes the originalstr
and returns the modifiedstr
.args (tuple[str, ...]) – Additional positional arguments for
func
.kwargs (dict[str, Any]) – Additional keyword arguments for
func
.
- Returns
Random word.
- Return type
- gen_sentence(comma, word_range)[source]¶
Generate random sentence.
- Parameters
comma (tuple[int, int]) – Random range for number of commas. The function will use
random.randint()
to choose a random integer as the number of commas.word_range (tuple[int, int]) – Random range for number of words in each sentence. The function will use
random.randint()
to choose a random integer as the number of words.
- Returns
Random sentence.
- Return type
- gen_paragraph(comma, word_range, sentence_range)[source]¶
Generate random paragraph.
- Parameters
comma (tuple[int, int]) – Random range for number of commas. The function will use
random.randint()
to choose a random integer as the number of commas.word_range (tuple[int, int]) – Random range for number of words in each sentence. The function will use
random.randint()
to choose a random integer as the number of words.sentence_range (tuple[int, int]) – Random range for number of sentences in each paragraph. The function will use
random.randint()
to choose a random integer as the number of sentences.
- Returns
Random paragraph.
- Return type
Module Unittests¶
Test suite for lorem module.
- test_lorem.islice(iterable, stop)[source]¶
Wrapper function for
itertools.islice()
.
- test_lorem.shuffle(x, random=None)[source]¶
Mock
random.shuffle()
, but actually do nothing.
- test_lorem.randint(a, b)[source]¶
Mock
random.randint()
, but return the lower boundary.
- test_lorem.choice_first(seq)[source]¶
Mock
random.choice()
, but return the first element.- Parameters
seq (Sequence[_T]) –
- Return type
_T
- test_lorem.choice_last(seq)[source]¶
Mock
random.choice()
, but return the last element.- Parameters
seq (Sequence[_T]) –
- Return type
_T
- test_lorem.pool(self, dupe=1)[source]¶
Mock
lorem.LoremGenerator._gen_pool()
, but return a minimised pool.- Parameters
self (lorem.LoremGenerator) –
dupe (int) –
- Return type
Iterator[str]
- class test_lorem.TestLorem(methodName='runTest')[source]¶
Bases:
TestCase
Unittest case for
lorem
module.- test_gen_word()[source]¶
Test
lorem.LoremGenerator.gen_word()
.- Return type
None
- test_gen_sentence()[source]¶
Test
lorem.LoremGenerator.gen_sentence()
.- Return type
None
- test_gen_paragraph()[source]¶
Test
lorem.LoremGenerator.gen_paragraph()
.- Return type
None
- test_word()[source]¶
Test
lorem.word()
.- Return type
None
- test_sentence()[source]¶
Test
lorem.sentence()
.- Return type
None
- test_paragraph()[source]¶
Test
lorem.paragraph()
.- Return type
None
- test_get_word()[source]¶
Test
lorem.get_word()
.- Return type
None
- test_get_sentence()[source]¶
Test
lorem.get_sentence()
.- Return type
None
- test_get_paragraph()[source]¶
Test
lorem.get_paragraph()
.- Return type
None
In publishing and graphic design, lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content.
The lorem
module provides a generic access to generating the lorem ipsum
text from its very original text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
est laborum.
Usage of the lorem
module is rather simple. Depending on your needs, the
lorem
module provides generation of words, sentences, and
paragraphs.
Get Random Words¶
The lorem
module provides two different ways for getting random words.
word()
– generate a list of random wordsdef word(count=1, func=None, args=(), kwargs={}) -> Iterator[str]: ...
get_word()
– return random wordsdef get_word(count=1, sep=' ', func=None, args=(), kwargs={}) -> str: ...
Get Random Sentences¶
The lorem
module provides two different ways for getting random sentences.
sentence()
– generate a list of random sentencesdef sentence(count=1, comma=(0, 2), word_range=(4, 8)) -> Iterator[str]: ...
get_sentence()
– return random sentencesdef get_sentence(count=1, sep=' ', comma=(0, 2), word_range=(4, 8)) -> Union[str]: ...
Get Random Paragraphs¶
The lorem
module provides two different ways for getting random paragraphs.
paragraph()
– generate a list of random paragraphsdef paragraph(count=1, comma=(0, 2), word_range=(4, 8), sentence_range=(5, 10)) -> Iterator[str]: ...
get_paragraph()
– return random paragraphsdef get_paragraph(count=1, sep=os.linesep, comma=(0, 2), word_range=(4, 8), sentence_range=(5, 10)) -> Union[str]: ...