Skip to main content

Minimalistic, standalone alternative fake data generator with no dependencies.

Project description

Minimalistic, standalone alternative fake data generator with no dependencies.

Overview

fake.py is a standalone and portable library that allows you to generate various types of random data for testing and other purposes. The package provides a simplified, dependency-free alternative for generating random words, sentences, paragraphs, file names, URLs, PDFs, images, person names and more.

Requirements

  • Python 3.8+

Installation

pip

pip install fake.py

Download and copy

fake.py is the sole, self-contained module of the package. It includes tests too. If it’s more convenient to you, you could simply download the fake.py module and include it in your repository.

Since tests are included, it won’t have a negative impact on your test coverage (you might need to apply tweaks to your coverage configuration).

Usage

Imports and initialization

from fake import Faker

FAKER = Faker()

first_name

Returns a random first name.

FAKER.first_name()

last_name

Returns a random last name.

FAKER.last_name()

name

Returns a random full name.

FAKER.name()

word

Returns a random word from the Zen of Python.

FAKER.word()

words

Returns a list of nb random words from the Zen of Python.

FAKER.words()

Arguments:

  • nb (type: int, default value: 5) is an optional argument.

sentence

Returns a random sentence with nb_words number of words.

FAKER.sentence()

Arguments:

  • nb_words (type: int, default value: 5) is an optional argument.

sentences

Returns nb number of random sentences.

FAKER.sentences()

Arguments:

  • nb (type: int, default value: 3) is an optional argument.

paragraph

Returns a random paragraph with nb_sentences number of sentences.

FAKER.paragraph()

Arguments:

  • nb_sentences (type: int, default value: 5) is an optional argument.

paragraphs

Returns nb number of random paragraphs.

FAKER.paragraphs()

Arguments:

  • nb (type: int, default value: 3) is an optional argument.

text

Returns random text with up to nb_chars characters.

FAKER.text()

Arguments:

  • nb_chars (type: int, default value: 200) is an optional argument.

file_name

Returns a random file name with the given extension.

FAKER.file_name()

Arguments:

  • extension (type: str, default value: txt) is an optional argument.

email

Returns a random email with the specified domain.

FAKER.email()

Arguments:

  • domain (type: str, default value: example.com) is an optional argument.

url

Returns a random URL.

FAKER.url()

Arguments:

  • protocols (type: Optional[Tuple[str]], default value: None) is an optional argument.

  • tlds (type: Optional[Tuple[str]], default value: None) is an optional argument.

  • suffixes (type: Optional[Tuple[str]], default value: None) is an optional argument.

pyint

Returns a random integer between min_value and max_value.

FAKER.pyint()

Arguments:

  • min_value (type: int, default value: 0) is an optional argument.

  • max_value (type: int, default value: 9999) is an optional argument.

pybool

Returns a random boolean value.

FAKER.pybool()

pystr

Returns a random string of nb_chars length.

FAKER.pystr()

Arguments:

  • nb_chars (type: int, default value: 20) is an optional argument.

pyfloat

Returns a random float between min_value and max_value.

FAKER.pyfloat()

Arguments:

  • min_value (type: float, default value: 0.0) is an optional argument.

  • max_value (type: float, default value: 10.00) is an optional argument.

ipv4

Returns a random IPv4 address.

FAKER.ipv4()

date_between

Generates a random date between start_date and end_date.

FAKER.date_between(start_date="-1d", end_date="+1d")

Arguments:

  • start_date (type: str) is a required argument.

  • end_date (type: str, default value: +0d) is an optional argument.

date_time_between

Generates a random datetime between start_date and end_date.

FAKER.date_time_between(start_date="-1d", end_date="+1d")

Arguments:

  • start_date (type: str) is a required argument.

  • end_date (type: str, default value: +0d) is an optional argument.

pdf

Generates a content (bytes) of a PDF document.

FAKER.pdf()

Arguments:

  • nb_pages (type: int, default value: 1) is an optional argument.

  • generator (type: Union[Type[TextPdfGenerator], Type[GraphicPdfGenerator]], default value: GraphicPdfGenerator) is an optional argument.

image

Generates a content (bytes) of a image of the specified format and colour.

FAKER.image()  # Supported formats are `png`, `svg`, `bmp` and `gif`

Arguments:

  • image_format (type: str, default value: png) is an optional argument.

  • size (type: Tuple[int, int], default value: (100, 100)) is an optional argument.

  • color (type: Tuple[int, int, int], default value: (0, 0, 255)) is an optional argument.

Tests

Run the tests with unittest:

python -m unittest

Or pytest:

pytest

Differences with Faker

fake.py is modeled after the famous Faker package. Its’ API is highly compatible, although drastically reduced. It’s not multilingual and does not support postal codes or that many RAW file formats. However, you could easily include it in your production setup without worrying about yet another dependency.

License

MIT

Author

Artur Barseghyan <artur.barseghyan@gmail.com>

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

fake.py-0.1.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

fake.py-0.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file fake.py-0.1.tar.gz.

File metadata

  • Download URL: fake.py-0.1.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for fake.py-0.1.tar.gz
Algorithm Hash digest
SHA256 17f1b61dcf6305515d94daa779ee083a724ae9d68f4470ab6331a4ed992316c6
MD5 3d41434f6d879579d93ec0c93b5e1d67
BLAKE2b-256 7d759a456db71ffea2b5700705407358bfd575d5dcd65fd5a25638df3a093e98

See more details on using hashes here.

File details

Details for the file fake.py-0.1-py3-none-any.whl.

File metadata

  • Download URL: fake.py-0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for fake.py-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10fbef974740658d44f1c24240cb1fba491818bc2904e701d97e29c68d82d989
MD5 f5c20bbce4d00735788af5d8b5c47364
BLAKE2b-256 4a67dd9cb3cfa89c6f91363a6d8ad1dd9cd26df0753009d08d2cde5b31a7f67c

See more details on using hashes here.

Supported by

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