Pyrallis - Simple Configuration with Dataclasses
Pyrausta (also called pyrallis (πυραλλίς), pyragones) is a mythological insect-sized dragon from Cyprus.
Pyrallis
is a simple library, derived from simple-parsing
, for automagically creating project configuration from a dataclass.
Why pyrallis
?
With pyrallis
your configuration is linked directly to your pre-defined dataclass
, allowing you to easily create different configuration structures, including nested ones, using an object-oriented design. The parsed arguments are used to initialize your dataclass
, giving you the typing hints and automatic code completion of a full dataclass
object.
Installing pyrallis
Installing pyrallis
is super-easy via PyPi
My First Pyrallis Example
There are several key features to pyrallis but at its core pyrallis simply allows defining an argument parser using a dataclass.
The arguments can then be specified using command-line arguments, a yaml
configuration file, or both
$ python train_model.py --config_path=some_config.yaml --exp_name=my_first_exp
Training my_first_exp with 42 workers...
Key Features
Building on that design pyrallis offers some really enjoyable features including
- Builtin IDE support for autocompletion and linting thanks to the structured config. 🤓
- Joint reading from command-line and a config file, with support for specifying default config_path for the
pyrallis.parse
call 😍 - Support for builtin dataclass features, such as
__post_init__
and@property
😁 - Support for nesting and inheritance of dataclasses, nested arguments are automatically created! 😲
- A magical
@pyrallis.wrap()
decorator for wrapping your main class 🪄
- Easy extension to new types using
pyrallis.encode.register
andpyrallis.decode.register
👽 - Easy loading and saving of existing configurations using
pyrallis.dump
andpyrallis.load
💾 - Magical
--help
creation from dataclasses, taking into account the comments as well! 😎 - Support for multiple configuration formats (
yaml
,json
,toml
) usingpyrallis.set_config_type
⚙️
That's basically it, see the rest of this documentation for more complete tutorial and info.