I'm trying to create a web interface for a data analysis pipeline using Pyramid. I'm using deform and colander to make the forms. I've been adapting this example:
http://pyramid-tutorials.readthedocs.org/en/latest/humans/security/step02/
Most of the work gets done when a form gets submitted, but there are a couple of generic steps that only need to run once. Can I load some things into memory when the server starts up so that they are accessible from within a view?
You can define some module level variables in the main file of your application (or may be somewhere else) and then use them by importing them as per your requirement.
I use this method to create settings like database connection string for SQLAlchemy from environment variables.
By default, a module will be parsed only once in Python, so you module level code will run only once.
Update 1
Let's assume directory structure of a pyramid project looks like this:
Let's say we've following code in
settings/redis.py
:You can use this
SOME_SETTING_STORED_IN_REDIS
variable from anywhere. If name of your app isexample_app
then inexample_app/views/home.py
you can use it like this:I think you're trying to achieve something similar.