Skip to main content

myopy, run blind python files.

Project description

tests

myopy

Run blind python files.

This single class package, provides python objects to a python file at run time. This is ideal for configuration files where the user does not need to know where an object comes from or how to initialize it. It allows the python file to be blind to the origin of it's objects, removing the need for imports, object initializations or convoluted subclassing.

This is pretty much a standalone clone of the way the amazing qutebrowser handles it's config files.

Feel free to copy paste the PyConfig class if you don't want the added dependency.

Installation

pip install myopy

Usage

Say you want to allow the user to change a dict containing some settings for an application in a configuration file called config.py:

In the application you would have something along the lines of:

from myopy import PyConfig

user_dict = {'something': 2}

config = PyConfig('path/to/config.py')
config.provide('settings', user_dict)  # we provide the config file the user_dict in the settings variable
out = config.run()  # out is a dict of the provided objects
print('after running config: ', user_dict)
print('out: ', out)

And in the user facing config.py, the user_dict object would be provided in the settings variable, and the user can change its values at will:

print('in config: ', settings)
settings['something_else'] = 4
settings['something'] = 3

The output would be:

in config: {'something': 2}
after running config: {'something': 3, 'something_else': 4}
out: {'settings': {'something': 3, 'something_else': 4}}

the user_dict is modified in place.

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

myopy-0.1.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

myopy-0.1.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file myopy-0.1.1.tar.gz.

File metadata

  • Download URL: myopy-0.1.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/2.7.15rc1 Linux/4.15.0-91-generic

File hashes

Hashes for myopy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cf7517d082a38fb3f1d6e4ca090bb0cb1581e51c29aa504123f91c104ba8d57f
MD5 ed9fa22eb8791124171da089c3b1feb7
BLAKE2b-256 da7aec77d6167cb50fe85d5ab8411b3dee1fa07d2b510bd5274a7e97eac5f451

See more details on using hashes here.

File details

Details for the file myopy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: myopy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/2.7.15rc1 Linux/4.15.0-91-generic

File hashes

Hashes for myopy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3129890aaa5fc796624956da469f4d7e0450036fbf6874d14d021094f0d896dc
MD5 7926876b470b7fe3bf5fafb1fa387808
BLAKE2b-256 582a5771d6154894107096bf4e376658ef215cdda37fff1b04ddb06d4fc51fab

See more details on using hashes here.

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