a mildly monadic module for fast faking
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fakir-0.1.tar.gz.
File metadata
- Download URL: fakir-0.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6878c092d195285e0bdf564a20183970d21254758db75346cf9fd9f12910b46
|
|
| MD5 |
0187383adb2eebef3d84b90b3a3421b7
|
|
| BLAKE2b-256 |
c801d6f62f8fd9bffd9b5c5b739f72dc1fffc3bdbdf8e30ed8514dad1d0f5352
|
File details
Details for the file fakir-0.1-py3-none-any.whl.
File metadata
- Download URL: fakir-0.1-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bb07f1961fd93fbe68974c66a38b471d15b8cdaf6c46bc73f72abc731fc8abc
|
|
| MD5 |
a510794eaa997088b39d503187a7ec88
|
|
| BLAKE2b-256 |
5b0cca2a216eb47d47c7349cfd5afef92d488c41bef6593f4d7edc8b6b904b3c
|