Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Introducing the Pyramid framework
Lecture: Building block: Configuration

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Configuration's a super important part of our web app. Like I described in the intro to this chapter there's certainly behaviors you would like
0:09 to be different in development than in production. A real simple is, do you send email notifications to users when you take certain actions?
0:19 Well, in production, of course you do that, right? I want to reset my password, or I purchased this thing.
0:25 If you're doing testing locally, especially if somebody comes to you and says, hey, the site's not working for me,
0:32 I tried this, but this happens, you might want to log in as that user and then try that action. And obviously you don't want them to get the email.
0:42 The easiest way to do this in Pyramid is to have different configuration files, both for development,
0:47 production, test, whatever the various scenarios you have are. In fact, when you create a new project,
0:53 it comes with a development.ini and a production.ini, and in here we have a bunch of settings that Pyramid uses to control itself.
1:01 But we can add other settings just by saying key equals value, so db_file=/db/webapp.sqlite, API key equals whatever that thing is.
1:13 Notice there's no quotes on the strings, they just come back as strings anyway. Super easy, we can do that. Now how do you get to them in Pyramid?
1:20 Well, we saw that main startup method, and the settings being passed in there, so that's super easy. We go to that again.
1:27 Now we can go to that config and say get us the settings, this is a dictionary that has those keys and values.
1:34 So if I want the DB file, I just say configsettings.get, and there's just standard Python dictionary access.
1:41 Get me the thing for DB file, get me the API key, and off you go. And obviously these can be different in development and production.


Talk Python's Mastodon Michael Kennedy's Mastodon