Skip to content

Instantly share code, notes, and snippets.

Created Jun 15, 2018
What would you like to do?
Loading python code into, and then running it from, a sqlite database
import sqlite3
import sys
import imp
from peewee import SqliteDatabase, Model, TextField
db = SqliteDatabase('code.sqlite3')
class Module(Model):
code = TextField()
name = TextField()
class Meta:
database = db
with open('') as f:
demo_module = Module(, name='demo')
def import_code(name, code):
module = imp.new_module(name)
exec(code) in module.__dict__
return module
m = Module.get()
import_code(, m.code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment