Introducing Anyfig!

Anyfig is a Python library for creating configurations (settings) at runtime. Anyfig utilizes Python classes which empowers the developer to put anything, from strings to custom objects in the config. Hence the name Any(con)fig.

Why Anyfig?#

Anyfig was developed for my own machine learning experiments but has since generalized to support other types of Python projects. Since the configs are defined in normal Python code, Anyfig offers freedom and flexibility that isn't possible with other solutions.

Features in a nutshell#

  • Work in Python. No reading from .json or .yaml (unless you want to)
  • Utilize Python code / packages to define configs at runtime
  • Avoid duplicated config-parameters with the help of inheritance and modularization
  • Override config-values via command line input
  • Freeze configs for immutability
  • Save / load configs

Basic Example#

import anyfig
from pathlib import Path
import time
@anyfig.config_class # Registers the class with anyfig
class MyConfig:
def __init__(self):
# Config-parameters goes as attributes
self.experiment_note = 'Changed stuff'
self.save_directory = Path('output')
self.start_time = time.time()
# Instantiate config object
config = anyfig.init_config(default_config=MyConfig)
# Access config values with the dot notation
print(config.start_time)

Feel free to play with the Online Demo hosted by Pyfiddle or start learning about Anyfig in the Fundamentals guide.

Citing Anyfig#

Feel free to cite Anyfig in your research:

@Misc{Anyfig,
author = {Olof Harrysson},
title = {Anyfig - Configuring complex Python applications},
howpublished = {Github},
year = {2020},
url = {https://github.com/OlofHarrysson/anyfig}
}