Ordered dataclass serializer mixin for sloted dataclasses
Project description
Slot Machine
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
Built Distribution
Close
Hashes for slot_machine_serializers-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9814f74054b3c2b05fb21e0eb1475694fd98daec6821fa031d5d5f3d9a4cf4ff |
|
MD5 | bce9ee901ad65a4b3a54e462bd632ce0 |
|
BLAKE2b-256 | 51c672d958bc532b5cbab07aff7efbd9d87228d6a2f8fdd5bb448cbb99a80a50 |
Close
Hashes for slot_machine_serializers-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b34315e6c50a196652134c03b2198c619973c56c2c3f3d71497564a16f048de |
|
MD5 | c1d217405398122036259849753f1717 |
|
BLAKE2b-256 | 748f9267fce435ebca336c81720baad3f9ca3adcc890b1ef01ed48136eb30c21 |