Ordered dataclass serializer mixin for sloted dataclasses
Project description
Slot Machine
Have you ever found yourself ruminating 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: !RangeSampler 5..20
price: !UniformSampler 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: !RangeSampler 5..10
price: !UniformSampler 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 SplitsSampler(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: !SplitsSampler
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.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c56293492aa1afbf0226c9d7eced749e39edb5d0a308d60a76d9b58f98a5a08 |
|
MD5 | fb16cf815333485e2f9b724800ca8c95 |
|
BLAKE2b-256 | 7e3c53c1e62ce9f6f6b16c12364e5b6e3aa171d4eec3391a4d27ab651089158b |
Close
Hashes for slot_machine_serializers-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f441991b14b066c7b96784561c7efeba0c1af280f11e84b49d4f4d6593a43056 |
|
MD5 | 280b52d8aee7e4f6ca9404716f50ca2b |
|
BLAKE2b-256 | 19ab272c8bcd358118afe55430a15d7f65ed4f3a329e00e42afda4b8fa0e4193 |