How to use Pyramid/models outside of WSGI/Paster

20 views
Skip to first unread message

somewhatofftheway

unread,
Jun 6, 2011, 8:13:55 PM6/6/11
to pylons-discuss
I'm new to Pyramid and can't figure out how to do something which
seems like it should be quite a common requirement.

Basically, I want to write a script that will use the database models
but will not need to do HTTP requests. The idea is that I can run it
by cron or whatever.

The equivalent in Pylons is answered here:

http://stackoverflow.com/questions/134387/run-pylons-controller-as-separate-app

Could anybody assist and tell me if there is a simple way to achieve
this? I have spent some time looking at Paster commands and the like
but without success.

Thanks,
Ben

Gael Pasgrimaud

unread,
Jun 8, 2011, 6:26:18 AM6/8/11
to pylons-...@googlegroups.com
Hi,

I guess that this thread already contain a reply:

http://groups.google.com/group/pylons-discuss/browse_thread/thread/fb1f4c49cf34eee2?hl=en#

But I'm agree that this point should be added in the pyramid
documentation with a recommended way to do that. It's a common need

--
Gael

> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
>
>

Benjamin Sims

unread,
Jun 10, 2011, 10:21:07 AM6/10/11
to pylons-...@googlegroups.com
Hi,

Thanks so much for your help; that enabled me to solve it. For convenience of anyone else, I did:

#Bring in pyramid application--------------------------------------

import pyramid
from paste.deploy import appconfig
config_file = '/path_to_config_file/configname.ini'

name = 'app_name'
config_name = 'config:%s' % config_file
here_dir = os.getcwd()

conf = appconfig(config_name, name, relative_to=here_dir)

from main_package import main
app = main(conf.global_conf, **conf.local_conf)

#--------------------------------------------------------------------------

I agree that a documented official way to achieve this would be good, I searched for quite a while and did not come across the answer.

Thanks again,
Ben

Thomas G. Willis

unread,
Jun 10, 2011, 11:58:56 AM6/10/11
to pylons-...@googlegroups.com
But that's really a python pastedeploy thing. you dont need the "import pyramid" to get the app initialized from configuration. 

Python Paste has docs, http://pythonpaste.org/deploy/#basic-usage


Maybe pyramids docs could elaborate on the capabilities of pastedeploy in this section.

However I think things like that would probably not be in scope, it's probably good enough that PasteDeploy is mentioned and curious users can go research themselves. :)
Reply all
Reply to author
Forward
0 new messages