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. ```python 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.0rc3.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.0rc3-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python-lorem-0.1.0rc3.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.0rc3.tar.gz
Algorithm Hash digest
SHA256 8fd21c094f3741bc3ed000390ea130aa43b118d14cddc25b00e8b69ecf3f01de
MD5 094131356607ec608367da262c772cb4
BLAKE2b-256 2209af63307cf6170c006adff2ec40f908aa742f967f9914ab21533df5e91af8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_lorem-0.1.0rc3-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.0rc3-py3-none-any.whl
Algorithm Hash digest
SHA256 43db8595bf1e0f41f8967db35902e2600005322fc92838ad98ef4b16087923cd
MD5 fd318b3ec14b26f5599f65800c258c71
BLAKE2b-256 00183a1e9a10c5e4c0c9a4d0705488536189b807837583aa30769df2e8b62c83

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