Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing global config variables in a Pyramid project

Tags:

python

pyramid

I'm just getting started with Python's pyramid framework and am unsure where to set application variables and the best way to import them into my project. For example: database username/passwords, paths, thumbnail height/width, etc ...

Should I create a dedicated config.py file and import the variables into my functions? What should this look like?

Thanks.

like image 964
ensnare Avatar asked Mar 06 '12 23:03

ensnare


1 Answers

There is a recipe in the cookbook for emulating the Django-style global settings file (for your convenience). However, the recommended way is to store these things in your INI file as deployment settings. Thus you could have one database username/password for development and one for production and it's as simple as having two INI files. All of the key/value pairs that you add to the [app:...] INI section for your Pyramid app are available at setup time and during request processing via a settings dictionary which is attached to the registry. This is accessible via config.registry.settings as well as request.registry.settings. The settings object is a copy of the dict that you passed into the Configurator(settings=settings, ...) within your main function.

For more information, see http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/startup.html as well as the tutorials within the Pyramid documentation which have examples of all of this.

like image 67
Michael Merickel Avatar answered Nov 10 '22 02:11

Michael Merickel