librelist archives

« back to archive

dynamically register blueprint...

dynamically register blueprint...

From:
Remy Pirson
Date:
2013-03-19 @ 15:27
hi,

I'm developing an application which needs to "dynamically" register a
blueprint.
So, is it possible to call "app.regester_blueprint()" after the "app.run()"
?
so define a new route when app is running ? it's essential...

Thx.

Re: [flask] dynamically register blueprint...

From:
Mark Grey
Date:
2013-03-19 @ 15:30
Hi!

Have you tried wrapping your app creation logic with a function?  You can
then parameterize the blueprints you need based off of config/environ, etc.
 This type of function is typically called `create_app()` in the Flask
example docs.  If you put your logic for attaching blueprints there you can
make sure the call to run comes after all the logic for attaching
blueprints has run.

Keep in mind that app.run() is only intended for local testing as well.

On Tue, Mar 19, 2013 at 11:27 AM, Remy Pirson <remy.pirson@gmail.com> wrote:

> hi,
>
> I'm developing an application which needs to "dynamically" register a
> blueprint.
> So, is it possible to call "app.regester_blueprint()" after the
> "app.run()" ?
> so define a new route when app is running ? it's essential...
>
> Thx.

Re: [flask] dynamically register blueprint...

From:
Remy Pirson
Date:
2013-03-19 @ 15:42
yes that's right but in fact, my flask application is a "web portal" which
group a lot of other applications (as blueprints). when app is running
(test) or when the app will be deployed, i would like to dynamically add an
new application (blueprint) to my portal WITHOUT restarting it (because a
lot of people will work on these applications). It's a bit difficult to
explain cause it's a very special use of blueprints...

2013/3/19 Mark Grey <mark.asperia@gmail.com>

> Hi!
>
> Have you tried wrapping your app creation logic with a function?  You can
> then parameterize the blueprints you need based off of config/environ, etc.
>  This type of function is typically called `create_app()` in the Flask
> example docs.  If you put your logic for attaching blueprints there you can
> make sure the call to run comes after all the logic for attaching
> blueprints has run.
>
> Keep in mind that app.run() is only intended for local testing as well.
>
>
> On Tue, Mar 19, 2013 at 11:27 AM, Remy Pirson <remy.pirson@gmail.com>wrote:
>
>> hi,
>>
>> I'm developing an application which needs to "dynamically" register a
>> blueprint.
>> So, is it possible to call "app.regester_blueprint()" after the
>> "app.run()" ?
>> so define a new route when app is running ? it's essential...
>>
>> Thx.
>
>
>

Re: [flask] dynamically register blueprint...

From:
Mark Grey
Date:
2013-03-19 @ 16:53
It does seem like a really specialized use case that's hard to give advice
for, but I think I understand what you mean.  What you require is a little
more low level than what Flask provides out of the box, since wsgi just
runs as a thin interface to another web server (nginx, apache with
mod_wsgi, or reverse proxying to gunicorn or cherry or some python server),
where things like restarting the service typically go on.  Keep in mind
that Flask itself is just a web microframework and not a service in of
itself - anything that requires an internal event that will change state of
the service (for instance, restarting the process via the os) is going to
have to happen at the webserver level.

If you need to swap up routes without bringing the whole server down,
my intuitions would dictate that you'll need to do something at the service
level itself using a library like Tornado or Twisted, since you'll need
async hooks to rebuild your routes without restarting.  Someone else may be
able to provide better guidance though.  I'm sure combinations of process
monitors and event listeners could approximate this as well.

It's worthy to note that you can still use flask for routing and request
wrappers with some of these networking frameworks (I've had success with
both Twisted and Tornado).  I actually vastly prefer how Flask handles
routing intuitively vs both those  stacks.

A pretty good approach using tornado with Flask for routing is outlined
here:
http://stackoverflow.com/questions/8143141/using-flask-and-tornado-together

You could then have hooks lower level into the Tornado service itself to
change it's internal state based off some event, be it an OS hook or
network event.

I'm sorry if that's still vague, but it's really the best advice I can give
with the info supplied.  Good luck!

On Tue, Mar 19, 2013 at 11:42 AM, Remy Pirson <remy.pirson@gmail.com> wrote:

> yes that's right but in fact, my flask application is a "web portal" which
> group a lot of other applications (as blueprints). when app is running
> (test) or when the app will be deployed, i would like to dynamically add an
> new application (blueprint) to my portal WITHOUT restarting it (because a
> lot of people will work on these applications). It's a bit difficult to
> explain cause it's a very special use of blueprints...
>
>
> 2013/3/19 Mark Grey <mark.asperia@gmail.com>
>
>> Hi!
>>
>> Have you tried wrapping your app creation logic with a function?  You can
>> then parameterize the blueprints you need based off of config/environ, etc.
>>  This type of function is typically called `create_app()` in the Flask
>> example docs.  If you put your logic for attaching blueprints there you can
>> make sure the call to run comes after all the logic for attaching
>> blueprints has run.
>>
>> Keep in mind that app.run() is only intended for local testing as well.
>>
>>
>> On Tue, Mar 19, 2013 at 11:27 AM, Remy Pirson <remy.pirson@gmail.com>wrote:
>>
>>> hi,
>>>
>>> I'm developing an application which needs to "dynamically" register a
>>> blueprint.
>>> So, is it possible to call "app.regester_blueprint()" after the
>>> "app.run()" ?
>>> so define a new route when app is running ? it's essential...
>>>
>>> Thx.
>>
>>
>>
>

Re: [flask] dynamically register blueprint...

From:
Pirson Rémy
Date:
2013-03-19 @ 19:00
Le 19/03/2013 17:53, Mark Grey a écrit :
> It does seem like a really specialized use case that's hard to give 
> advice for, but I think I understand what you mean.  What you require 
> is a little more low level than what Flask provides out of the box, 
> since wsgi just runs as a thin interface to another web server (nginx, 
> apache with mod_wsgi, or reverse proxying to gunicorn or cherry or 
> some python server), where things like restarting the service 
> typically go on.  Keep in mind that Flask itself is just a web 
> microframework and not a service in of itself - anything that requires 
> an internal event that will change state of the service (for instance, 
> restarting the process via the os) is going to have to happen at the 
> webserver level.
>
> If you need to swap up routes without bringing the whole server down, 
> my intuitions would dictate that you'll need to do something at the 
> service level itself using a library like Tornado or Twisted, since 
> you'll need async hooks to rebuild your routes without restarting. 
>  Someone else may be able to provide better guidance though.  I'm sure 
> combinations of process monitors and event listeners could approximate 
> this as well.
>
> It's worthy to note that you can still use flask for routing and 
> request wrappers with some of these networking frameworks (I've had 
> success with both Twisted and Tornado).  I actually vastly prefer how 
> Flask handles routing intuitively vs both those  stacks.
>
> A pretty good approach using tornado with Flask for routing is 
> outlined here:
> http://stackoverflow.com/questions/8143141/using-flask-and-tornado-together
>
> You could then have hooks lower level into the Tornado service itself 
> to change it's internal state based off some event, be it an OS hook 
> or network event.
>
> I'm sorry if that's still vague, but it's really the best advice I can 
> give with the info supplied.  Good luck!
>
> On Tue, Mar 19, 2013 at 11:42 AM, Remy Pirson <remy.pirson@gmail.com 
> <mailto:remy.pirson@gmail.com>> wrote:
>
>     yes that's right but in fact, my flask application is a "web
>     portal" which group a lot of other applications (as blueprints).
>     when app is running (test) or when the app will be deployed, i
>     would like to dynamically add an new application (blueprint) to my
>     portal WITHOUT restarting it (because a lot of people will work on
>     these applications). It's a bit difficult to explain cause it's a
>     very special use of blueprints...
>
>
>     2013/3/19 Mark Grey <mark.asperia@gmail.com
>     <mailto:mark.asperia@gmail.com>>
>
>         Hi!
>
>         Have you tried wrapping your app creation logic with a
>         function?  You can then parameterize the blueprints you need
>         based off of config/environ, etc.  This type of function is
>         typically called `create_app()` in the Flask example docs.  If
>         you put your logic for attaching blueprints there you can make
>         sure the call to run comes after all the logic for attaching
>         blueprints has run.
>
>         Keep in mind that app.run() is only intended for local testing
>         as well.
>
>
>         On Tue, Mar 19, 2013 at 11:27 AM, Remy Pirson
>         <remy.pirson@gmail.com <mailto:remy.pirson@gmail.com>> wrote:
>
>             hi,
>
>             I'm developing an application which needs to "dynamically"
>             register a blueprint.
>             So, is it possible to call "app.regester_blueprint()"
>             after the "app.run()" ?
>             so define a new route when app is running ? it's essential...
>
>             Thx. 
>
>
>
>
ok, thx for your rapid answer. In fact, i've already implemented a low 
level hook (with signals). When a defined signal is catched, the app 
just call a reload method which import all the plugins available, 
register them, take the url and put them into a dictionary i give to my 
main template. I'm gonna have a look at server side wsgi. thx for your 
pieces of advice.

Re: [flask] dynamically register blueprint...

From:
dorian i
Date:
2013-03-23 @ 02:49
Maybe post here exactly what you are trying to do and maybe we can find
another way for you to implement it?

On Tue, Mar 19, 2013 at 8:00 PM, Pirson Rémy <remy.pirson@gmail.com> wrote:

>  Le 19/03/2013 17:53, Mark Grey a écrit :
>
> It does seem like a really specialized use case that's hard to give advice
> for, but I think I understand what you mean.  What you require is a little
> more low level than what Flask provides out of the box, since wsgi just
> runs as a thin interface to another web server (nginx, apache with
> mod_wsgi, or reverse proxying to gunicorn or cherry or some python server),
> where things like restarting the service typically go on.  Keep in mind
> that Flask itself is just a web microframework and not a service in of
> itself - anything that requires an internal event that will change state of
> the service (for instance, restarting the process via the os) is going to
> have to happen at the webserver level.
>
>  If you need to swap up routes without bringing the whole server down,
> my intuitions would dictate that you'll need to do something at the service
> level itself using a library like Tornado or Twisted, since you'll need
> async hooks to rebuild your routes without restarting.  Someone else may be
> able to provide better guidance though.  I'm sure combinations of process
> monitors and event listeners could approximate this as well.
>
>  It's worthy to note that you can still use flask for routing and request
> wrappers with some of these networking frameworks (I've had success with
> both Twisted and Tornado).  I actually vastly prefer how Flask handles
> routing intuitively vs both those  stacks.
>
>  A pretty good approach using tornado with Flask for routing is outlined
> here:
> http://stackoverflow.com/questions/8143141/using-flask-and-tornado-together
>
>  You could then have hooks lower level into the Tornado service itself to
> change it's internal state based off some event, be it an OS hook or
> network event.
>
>  I'm sorry if that's still vague, but it's really the best advice I can
> give with the info supplied.  Good luck!
>
> On Tue, Mar 19, 2013 at 11:42 AM, Remy Pirson <remy.pirson@gmail.com>wrote:
>
>> yes that's right but in fact, my flask application is a "web portal"
>> which group a lot of other applications (as blueprints). when app is
>> running (test) or when the app will be deployed, i would like to
>> dynamically add an new application (blueprint) to my portal WITHOUT
>> restarting it (because a lot of people will work on these applications).
>> It's a bit difficult to explain cause it's a very special use of
>> blueprints...
>>
>>
>> 2013/3/19 Mark Grey <mark.asperia@gmail.com>
>>
>>> Hi!
>>>
>>> Have you tried wrapping your app creation logic with a function?  You
>>> can then parameterize the blueprints you need based off of config/environ,
>>> etc.  This type of function is typically called `create_app()` in the Flask
>>> example docs.  If you put your logic for attaching blueprints there you can
>>> make sure the call to run comes after all the logic for attaching
>>> blueprints has run.
>>>
>>> Keep in mind that app.run() is only intended for local testing as well.
>>>
>>>
>>> On Tue, Mar 19, 2013 at 11:27 AM, Remy Pirson <remy.pirson@gmail.com>wrote:
>>>
>>>> hi,
>>>>
>>>> I'm developing an application which needs to "dynamically" register a
>>>> blueprint.
>>>> So, is it possible to call "app.regester_blueprint()" after the
>>>> "app.run()" ?
>>>> so define a new route when app is running ? it's essential...
>>>>
>>>> Thx.
>>>
>>>
>>>
>>
>  ok, thx for your rapid answer. In fact, i've already implemented a low
> level hook (with signals). When a defined signal is catched, the app just
> call a reload method which import all the plugins available, register them,
> take the url and put them into a dictionary i give to my main template. I'm
> gonna have a look at server side wsgi. thx for your pieces of advice.
>