AppConfig documentation?

532 views
Skip to first unread message

Andrew Buchan

unread,
Feb 13, 2016, 11:02:26 AM2/13/16
to web2py-users
Hello, 

Newer versions of web2py seem to use an AppConfig object in the model, but I can't find any documentation for how this works anywhere in the manual...

Where am I supposed to create this file? What do I call it? What should I put in there?

Thanks.

Nico de Groot

unread,
Feb 13, 2016, 12:26:02 PM2/13/16
to web2py-users
From the source:

appconfig.py:

Read from configuration files easily without hurting performance.

USAGE:
During development you can load a config file either in .ini or .json format (by default app/private/appconfig.ini or app/private/appconfig.json)
The result is a dict holding the configured values. Passing reload=True is meant only for development: in production, leave reload to False and all values will be cached

from gluon.contrib.appconfig import AppConfig
myconfig = AppConfig(path_to_configfile, reload=False)
print myconfig['db']['uri']

The returned dict can walk with "dot notation" an arbitrarely nested dict

. print myconfig.take('db.uri')

You can even pass a cast function, i.e.

. print myconfig.take('auth.expiration', cast=int)

Once the value has been fetched (and casted) it won't change until the process is restarted (or reload=True is passed).

Please search in this group for more info.

Nico de Groot

Andrew Buchan

unread,
Feb 14, 2016, 10:46:46 AM2/14/16
to web...@googlegroups.com
Hi Nico,

Thanks for that!

I suppose this should really go into the web2py book, we can't expect people to read the source for something as basic (i.e. not an advanced feature or special use case) as this.

I'm happy to go into github and create a pull request, I'm just not sure where we should place this.

Perhaps we should add a section at the top of:


Or maybe it requires a section of its own?

I also think something should be mentioned in:





--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/1sBjyKQSY-U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niphlod

unread,
Feb 15, 2016, 3:24:00 AM2/15/16
to web2py-users
appconfig is a contrib module, for which we don't keep docs around, nor promise backward compatibility (although it's a pretty simple module)...
there's absolutely nothing to be documented, the scaffolding app uses pretty much all the features ^_^
Reply all
Reply to author
Forward
0 new messages