Skip to main content

Ordered dataclass serializer mixin for sloted dataclasses

Project description

Slot Machine

tests

Have you ever found yourself unclear over which configuration to choose?

Don't choose.

Randomize.

With slot_machine you can now sample any configuration.

Can't settle on a background color? Randomize...

Looking for a reasonable model parameter? Randomize...

Don't know what to eat on Sunday? Randomize...

With slot_machine your next choice will be one you look forward to.

Examples

Simply add your favorite samplers to the configuration:

chicken_nuggets: !SampleRange 5..20
price: !SampleUniform 9.99..20

Specify your dataclass and get rolling:

from dataclasses import dataclass
from slot_machine import SlotsSerializer

@dataclass(slots=True)
class Basket(SlotsSerializer):
    chicken_nuggets: int
    price: float

yaml_file = """
basket:
  chicken_nuggets: !SampleRange 5..10
  price: !SampleUniform 9.99..20
"""

surprise_basket = Basket.from_yaml(yaml_file)

Build your own

from dataclasses import dataclass
from slot_machine import SlotsSerializer, MappingSampler

@dataclass(slots=True)
class Basket(SlotsSerializer):
    chicken_nuggets: int
    splits: list[int]

class SampleSplits(MappingSampler):

  @classmethod
  def get_sample(cls, n_splits: str, values: str):
    n_splits = int(n_splits)
    values = list(map(int, values.split("..")))
    return sorted([random.randint(*values) for _ in range(n_splits)])
    
yaml_file = """
basket:
  chicken_nuggets: 100
  splits: !SampleSplits
    n_splits: 3
    values: 0..100
"""

surprise_basket = Basket.from_yaml(yaml_file)

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

slot_machine_serializers-0.4.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

slot_machine_serializers-0.4.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file slot_machine_serializers-0.4.0.tar.gz.

File metadata

File hashes

Hashes for slot_machine_serializers-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b54312f5d61086769975956e56bbb468945a7475c5d736573a76a8ddaa9560c0
MD5 780373515589ffcd6dc3c15b279e9384
BLAKE2b-256 ddda632583e04996eebf1a10ce925acfc777cbf53079668f63f44acaf161b878

See more details on using hashes here.

File details

Details for the file slot_machine_serializers-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for slot_machine_serializers-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b81fcef766dedaef7ed5883267043f1b7a8f11343ef191614f8b10f32e0cade0
MD5 2213c393cf3f08600d41da5d00b5ad16
BLAKE2b-256 184df59d7fd206c20aa08553c8d24c6631078bef0e592ee7c9e05c852e6c8ab0

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