Skip to main content

My Personal Configuration System for Python

Project description

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)

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

mpcspy-0.0.3.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

mpcspy-0.0.3-py3.8.egg (5.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page