Skip to main content

fluffycow

https://travis-ci.org/ChrisTimperley/fluffycow.svg?branch=master https://badge.fury.io/py/fluffycow.svg https://img.shields.io/pypi/pyversions/fluffycow.svg

A simple and elegant library for generating complex random objects in Python.

https://static.boredpanda.com/blog/wp-content/uploads/2014/03/cute-fluffy-animals-33.jpg

(image credit: Matt Lautner.)

Installation

To install the latest release from PyPI:

$ pip install fluffycow

To install the latest development release:

$ git clone https://github.com/ChrisTimperley/fluffycow
$ cd fluffycow
$ python setup.py install

Examples

To generate 10 lists containing 5 random numbers:

import fluffycow as g

gen = g.list(g.random(), 5)
for i in range(10):
    l = next(gen)
    print(l)

"""
[0.8620918485892981, 0.4794836848262348, 0.262162063050416, 0.01909426938513137, 0.36506899628784006]
[0.9397902843125912, 0.9883123343094299, 0.5728170848781718, 0.2430986751635641, 0.6504376531611539]
[0.6530962809522628, 0.629805285301596, 0.7484217313556808, 0.4781887755635098, 0.7702516815623411]
[0.6049464336804768, 0.6857354552123759, 0.4401119070721792, 0.16269631684472152, 0.4501522526776762]
[0.6754685790929789, 0.14883325162091654, 0.7543575544723128, 0.7400186451945051, 0.7872586706933858]
[0.6093352430215464, 0.601878065077082, 0.9864251783225236, 0.5652106608585465, 0.2000072917817054]
[0.5288773016226057, 0.3473820645776373, 0.5181819860433858, 0.9795605815396756, 0.0941069188895195]
[0.577403816680611, 0.6006088487133505, 0.7401053882982396, 0.9243339819764703, 0.8737058738019327]
[0.15168246955860343, 0.9826794936881696, 0.8700116634339362, 0.23066589924280112, 0.6455718073363804]
[0.4953407037944514, 0.4235910957127196, 0.9817109582233142, 0.19140229868504488, 0.4238482591507997]
"""

To generate 5 random cows 🐄:

import fluffycow as g
import attr

@attr.s
class Cow:
   age = attr.ib(type=int)
   fluffiness = attr.ib(type=float)

# provide generators for each keyword argument,
gen = g.factory(Cow,
                age=g.randint(0, 50),
                fluffiness=g.gauss(5.0, 1.5))

# or for each positional argument,
gen = g.factory(Cow, g.randint(0, 50), g.gauss(5.0, 1.5))

# or mix positional and keyword arguments
gen = g.factory(Cow,
                g.randint(0, 50),
                fluffiness=g.gauss(5.0, 1.5))

# generate some fluffy cows
for i in range(5):
   cow = next(gen)
   print(cow)

"""
Cow(age=16, fluffiness=6.737730437364233)
Cow(age=30, fluffiness=3.6106200949734806)
Cow(age=4, fluffiness=5.856278892241928)
Cow(age=40, fluffiness=4.274460173984223)
Cow(age=8, fluffiness=4.26886806010291)
"""

To generate a farm containing a random mixture of 10 animals:

@attr.s
class Cow:
   age = attr.ib(type=int)
   fluffiness = attr.ib(type=float)

@attr.s
class Chicken:
    sass = attr.ib(type=int)

@attr.s
class Sheep:
   fluffiness = attr.ib(type=float)

def farm():
    cows = g.factory(Cow,
             age=g.randint(0, 30),
             fluffiness=g.gauss(5.0, 1.5))
    chickens = g.object(Chicken, g.randint(0, 10))
    sheep = g.object(Sheep, g.gauss(4.5, 1.0))

    animals = g.mux(cows, chickens, sheep)
    for i in range(10):
        animal = next(animals)
        print(animal)

"""
Cow(age=15, fluffiness=4.13522619329628)
Cow(age=6, fluffiness=6.132266751335851)
Sheep(fluffiness=4.996947740687185)
Cow(age=25, fluffiness=4.268442712380023)
Sheep(fluffiness=4.92952572321737)
Chicken(sass=5)
Cow(age=28, fluffiness=5.155204522890905)
Sheep(fluffiness=3.9241924681246094)
Sheep(fluffiness=3.676097181435127)
Sheep(fluffiness=2.713429568549102)
"""

Metadata

Release files for fluffycow 0.0.5

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

Source distribution (sdist)

Source distribution for fluffycow 0.0.5
File Size Uploaded Provenance
fluffycow-0.0.5.tar.gz 4.2 kB Without provenance Details

Release files / fluffycow-0.0.5.tar.gz

Download URL fluffycow-0.0.5.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cdcee1e57d270fb0f75a64cb9bacbd93f28f3ccd9fad07167c64ee6f1003cd8f
BLAKE2b-256 checksum
How to use checksums
18c416f2c7623f440bd5576fa132341917cd305f70d2590547c76ebe67a0ecc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

Security for fluffycow 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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