Skip to content

MPCSPY is My Personal Configuration System for Python

License

Notifications You must be signed in to change notification settings

goktug97/mpcspy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My Personal Configuration System for Python MPCSPY

I like to use Python as a configuration file. I have added some security features using AST module to prevent injecting malicious code to config files.

Requirements

  • Python >= 3.6 (fstrings)

Install

PyPI

pip3 install mpcspy

Source

git clone https://github.com/goktug97/mpcspy
cd mpcspy
python3 setup.py install

Example

  • Config File
#!/usr/bin/env python3

import dataclasses
import numpy as np

@dataclasses.dataclass
class Robot(object):
    width: float = 1.2 # [m]
    height: float = 0.5 # [m]
    max_angular_velocity: float = np.radians(40.0) # [rad/s]
  • Reading Config
import mpcspy
config = mpcspy.read_config(config_file = 'config',
        allowed_modules={'numpy': ['radians'],
            'dataclasses': ['dataclass']},
        allowed_functions=[],
        verbose=True)
print(config.Robot.width)
print(config.Robot.height)
print(config.Robot.max_angular_velocity)
  • Config File
#!/usr/bin/env python3

from os import path

dataset_path = path.join('./data/')
  • Reading Config
import mpcspy
config = mpcspy.read_config(config_file = 'config',
        allowed_modules={'os': ['path'],
            'path': ['join']},
        allowed_functions=[],
        verbose=True)