Skip to main content

fakir

a mildly monadic module for fast faking

A deliberately minimalist library for building graphs of random number generators with interesting dependencies, and running them to generate plausible-looking "fake data" for a variety of domains.

Pure Python with type annotations; depends only on the standard random module.

Let's generate some bogus data with a vaguely oil-and-gas flavor:

from fakir import fixed, rng_fn, uniform, normal, choice, tupled, ifelse
from random import Random
import sys

from typing import List

def main(argv: List[str]) -> int:
    animal = choice(['Wolf', 'Eagle', 'Cheetah'])
    geo = choice(['Outcrop', 'Karst', 'Tundra'])

    formation = animal + fixed(' ') + geo

    area = normal(40, 10)
    height = uniform(10, 100)
    volume = area * height

    phase = choice(['Oil', 'Gas'])
    price = ifelse(phase == fixed('Oil'),
        uniform(30, 60),
        uniform(1.5, 4.5)
    )

    row = tupled(formation, area, height, volume, phase, price, area.iid(), price.iid())

    r = Random(12345)
    for i in range(100):
        print(row.generate(r))

    return 0

if __name__ == '__main__':
    sys.exit(main(sys.argv))

fakir is "monad-inspired": there's an explicit bind, but graphs are implicitly monadic by default. That is, in the example above, price generates prices corresponding to the phase generated by phase in a given "generation cycle"---it's as if we really had written (using the phase and price produced "tupled" by phase_price):

phase = choice(['Oil', 'Gas'])
phase_price = phase.bind(
        lambda p: (
            uniform(30, 60) if p == 'Oil' else uniform(1.5, 4.5)
        ).fmap(lambda pr: (p, pr))) 

To "opt out" of this implicit bind, clone Fakir objects into independent identically distributed objects with the iid method.

Why is this a "package" and not a "module"? PEP 561 says that's the only way to get type information distributed (with py.typed). Someone who actually cares enough to bother should start a petition or something, because this kind of unbridled complexity addiction is what's destroying Python and the last shreds of my sanity.

View the full pdoc3-generated API documentation.

Install with: pip install fakir

Or download directly from PyPI.

(c) 2020 dwt | terminus data science, LLC

available under the Apache License 2.0

Metadata

Release files for fakir 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fakir 0.1
File Size Uploaded
fakir-0.1.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fakir 0.1
File Interpreter ABI Platform
fakir-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.8 kB

Release files / fakir-0.1.tar.gz

Download URL fakir-0.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e6878c092d195285e0bdf564a20183970d21254758db75346cf9fd9f12910b46
BLAKE2b-256 checksum
How to use checksums
c801d6f62f8fd9bffd9b5c5b739f72dc1fffc3bdbdf8e30ed8514dad1d0f5352
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / fakir-0.1-py3-none-any.whl

Download URL fakir-0.1-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bb07f1961fd93fbe68974c66a38b471d15b8cdaf6c46bc73f72abc731fc8abc
BLAKE2b-256 checksum
How to use checksums
5b0cca2a216eb47d47c7349cfd5afef92d488c41bef6593f4d7edc8b6b904b3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page