Skip to main content

myopy, run blind python files.

Project description

tests pypi

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 PyFile 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 PyFile

user_dict = {'something': 2}

config = PyFile('path/to/config.py')
config.provide('settings', user_dict)  # we provide the config file the user_dict in the settings variable
module = config.run()  # returns a module object
print('after running config: ', user_dict)
print('module: ', module)

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}
module: <module 'config' from 'path/to/config.py'>

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-1.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

myopy-1.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: myopy-1.1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/2.7.17 Linux/4.15.0-96-generic

File hashes

Hashes for myopy-1.1.0.tar.gz
Algorithm Hash digest
SHA256 150f6abc9723b752e2762032c31f76ca7a9b0385d9a4da91a9cf36c4f960820e
MD5 314686e6d811058c579c579bb4c3ea62
BLAKE2b-256 536c5cd2bba23de3069e37c1eac8016fe8d771cccd4dc29445c3bff2ddaad78d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: myopy-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/2.7.17 Linux/4.15.0-96-generic

File hashes

Hashes for myopy-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a28760b38084a838d86c031f0a31bd9797a0f5243ece149a9fe70aa31a06ba1
MD5 3de5fcd28e051c57068befd7f9dcc364
BLAKE2b-256 c1423fa6e221094adca4a4b9c72fe0777d725a50311a8142c4b56d49d9913481

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