Skip to main content

Lorem ipsum generator

Project description

Lorem ipsum generator

PyPI - Downloads PyPI - Version PyPI - Format PyPI - Python Version

Travis CI - Status Codecov - Coverage License LICENSE


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.

Installation

Note that the lorem module only supports Python versions since 3.3 🐍

Simply run the following to install the current version from PyPI:

pip install python-lorem

Or install the latest version from the git repository:

git clone https://github.com/JarryShaw/lorem.git
cd lorem
pip install -e .
# and to update at any time
git pull

Usage

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.

  1. def word(count=1, func=None, args=[], kwargs={}) -> Iterable[str]: ...
    

    Generate a list of random words.

    >>> list(word(count=3))
    ['labore', 'tempor', 'commodo']
    >>> list(word(count=3, func='capitalize'))
    ['Ea', 'Lorem', 'Do']
    >>> list(word(count=3, func=lambda s: s.upper()))
    ['UT', 'AMET', 'EXCEPTEUR']
    
    • Args:

      • count -- int

        Number of random words.

        default: 1

      • func -- Optional[Union[str, Callable[[str], str]]]

        Filter function. It can be an attribute name of str, or a customised function that takes the original str and returns the modified str.

        default: None

      • args -- List[str]

        Additional positional arguments for func.

        default: []

      • kwargs -- Dict[str, Any]

        Additional keyword arguments for func.

        default: {}

    • Returns:

      • Iterable[str] -- random words generator

  1. def get_word(count=1, sep=' ', func=None, args=[], kwargs={}) -> str: ...
    

    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'
    
    • Args:

      • count -- Union[int, Tuple[int]]

        Number of random words. To generate random number of words, supply a 2-element tuple of int, the function will use random.randint to choose a random integer as the number of random words.

        default: 1

      • sep -- str

        Seperator between each word.

        default: ' '

      • func -- Optional[Union[str, Callable[[str], str]]]

        Filter function. It can be a function name of str, or a customised function that takes the original str and returns the modified str.

        default: None

      • args -- List[str]

        Additional positional arguments for func.

        default: []

      • kwargs -- Dict[str, Any]

        Additional keyword arguments for func.

        default: {}

    • Returns:

      • str -- random words

Get random sentences

The lorem module provides two different ways for getting random sentences.

  1. def sentence(count=1, comma=(0, 2), word_range=(4, 8)) -> Iterable[str]: ...
    

    Generate a list of random sentences.

    >>> list(sentence())
    ['Aute irure et commodo sunt do duis dolor.']
    
    • Args:

      • count -- int

        Number of random sentences.

        default: 1

      • comma -- Tuple[int]

        Random range for number of commas. The function will use random.randint to choose a random integer as the number of commas.

        default: (0, 2)

      • word_range -- Tuple[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.

        default: (4, 8)

    • Returns:

      • Iterable[str] -- random sentence generator

  1. def get_sentence(count=1, comma=(0, 2), word_range=(4, 8), sep=' ') -> Union[str]: ...
    

    Return random sentences.

    >>> get_sentence()
    'Nostrud laboris lorem minim sit culpa, aliqua nostrud in amet, sint pariatur eiusmod esse.'
    
    • Args:

      • count -- Union[int, Tuple[int]]

        Number of random sentences. To generate random number of sentences, supply a 2-element tuple of int, the function will use random.randint to choose a random integer as the number of random sentences.

        default: 1

      • comma -- Tuple[int]

        Random range for number of commas. The function will use random.randint to choose a random integer as the number of commas.

        default: (0, 2)

      • word_range -- Tuple[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.

        default: (4, 8)

      • sep -- str

        Seperator between each sentence.

        default: ' '

    • Returns:

      • str -- random sentences

Get random paragraphs

The lorem module provides two different ways for getting random paragraphs.

  1. def paragraph(count=1, comma=(0, 2), word_range=(4, 8), sentence_range=(5, 10)) -> Iterable[str]: ...
    

    Generate a list of random paragraphs.

    >>> list(paragraph())
    ['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.']
    
    • Args:

      • count -- int

        Number of random paragraphs.

        default: 1

      • comma -- Tuple[int]

        Random range for number of commas. The function will use random.randint to choose a random integer as the number of commas.

        default: (0, 2)

      • word_range -- Tuple[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.

        default: (4, 8)

      • sentence_range -- Tuple[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.

        default: (5, 10)

    • Returns:

      • Iterable[str] -- random paragraph generator

  1. def get_paragraph(count=1, comma=(0, 2), word_range=(4, 8), sentence_range=(5, 10)) -> Union[str]: ...
    

    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.'
    
    • Args:

      • count -- int

        Number of random paragraphs. To generate random number of paragraphs, supply a 2-element tuple of int, the function will use random.randint to choose a random integer as the number of random paragraphs.

        default: 1

      • comma -- Tuple[int]

        Random range for number of commas. The function will use random.randint to choose a random integer as the number of commas.

        default: (0, 2)

      • word_range -- Tuple[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.

        default: (4, 8)

      • sentence_range -- Tuple[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.

        default: (5, 10)

      • sep -- str

        Seperator between each paragraph.

        default: ' '

    • Returns:

      • str -- random paragraphs

Internal APIs

Following are internal APIs for the lorem module.

  1. _TEXT: Tuple[str] = ('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')
    

    Original lorem ipsum text pool.

  1. def _gen_pool(dupe=1) -> Iterable[str]: ...
    

    Generate word pool.

    • Args:

      • dupe -- int

        Duplication to generate the word pool.

        default: 1

    • Returns

      • Iterable[str] -- an infinite loop word pool

  1. def _gen_word(pool, func, args=[], kwargs={}) -> str: ...
    

    Generate random word.

    • Args:

      • pool -- Iterable[str]

        Word pool, returned by _gen_pool.

      • func -- Optional[Union[str, Callable[[str], str]]]

        Filter function. It can be an attribute name of str, or a customised function that takes the original str and returns the modified str.

      • args -- List[str]

        Additional positional arguments for func.

        default: []

      • kwargs -- Dict[str, Any]

        Additional keyword arguments for func.

        default: {}

    • Returns:

      • str -- random word

  1. def _gen_sentence(pool, comma, word_range) -> str: ...
    

    Generate random sentence.

    • Args:

      • pool -- Iterable[str]

        Word pool, returned by _gen_pool.

      • comma -- Tuple[int]

        Random range for number of commas. The function will use random.randint to choose a random integer as the number of commas.

        default: (0, 2)

      • word_range -- Tuple[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.

        default: (4, 8)

    • Returns:

      • str -- random sentence

  1. def _gen_paragraph(pool, comma, word_range, sentence_range) -> str: ...
    

    Generate random paragraph.

    • Args:

      • pool -- Iterable[str]

        Word pool, returned by _gen_pool.

      • comma -- Tuple[int]

        Random range for number of commas. The function will use random.randint to choose a random integer as the number of commas.

        default: (0, 2)

      • word_range -- Tuple[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.

        default: (4, 8)

      • sentence_range -- Tuple[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.

        default: (5, 10)

    • Returns:

      • str -- random paragraph

Testing

The lorem module utilised unittest.mock to patch the builtin functions from random module. Test cases can be found in test.py. Contributions are welcome.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-lorem-0.1.0rc2.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_lorem-0.1.0rc2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file python-lorem-0.1.0rc2.tar.gz.

File metadata

  • Download URL: python-lorem-0.1.0rc2.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for python-lorem-0.1.0rc2.tar.gz
Algorithm Hash digest
SHA256 eac8719e56ff9769fcfc70535a0c27da923ba64f6333c92cb2b303087dbcee0a
MD5 80d265de7d74e04be6776c193cbc1d11
BLAKE2b-256 482fe9416cd4221cd43e01e85be8f92790b429e1f40325f468235bb2febe2942

See more details on using hashes here.

File details

Details for the file python_lorem-0.1.0rc2-py3-none-any.whl.

File metadata

  • Download URL: python_lorem-0.1.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for python_lorem-0.1.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 529c25ccc2846ff96f18a4ef73b065d36f8acaa9ee5e2fd1e8170349687b0d96
MD5 2a83d8ff7a52a80391934cb9c7d079ba
BLAKE2b-256 51106b2c20bb08382eb0b46b253b52c66b12cda5fa068978023f100a721bf364

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page