Python REST frameworks for App Engine? - python

Any pointers, advice on implementing a REST API on App Engine with Python? Using webapp for the application itself.
What I currently know is that I can:
hack up my own webapp handlers for handling REST-like URIs, but this seems to lose its elegance for larger amounts of resources. I mean, it's simple when it comes to temperature/atlanta, but not so much* for even a rather simple /users/alice/address/work (though do keep in mind that I'm not saying this after having implemented that, just after spending some time trying to design an appropriate handler, so my perception may be off).
use the REST functionality provided by one of the bigger Python web frameworks out there. I have some unexplainable sympathy towards web2py, but, since it's not used for the project, bundling it with the application just to provide some REST functionality seems.. overkill?
(Huh, looks like I don't like any of these approaches. Tough.)
So here's me asking: what advice, preferably based on experience, would you have for me here? What are my options, is my view of them correct, did I miss something?
Thanks in advance.

I had a similar issue. Wanting to quickly get my DataStore exposed via REST to WebApps.
Found: AppEngine REST Server.
I have only used it lightly so far, but it certainly appears to be very useful with a small amount of work. And it does use webapp as you suggested.

ProtoRPC is bundled with the SDK, and it is robust and actively developed (however experimental). Although I think the source code itself is a little convoluted, the feature-set is pretty complete and it was made by someone with experience in creating this kind of library. It supports transmiting using JSON, ProtocolBuffer and URL-encoded formats.
Also, you can create APIs that work on the server side and client side -- it defines a 'message' protocol with implementations in Python and JavaScript. I used other "RESTful" Python libraries, but no other provided this consistency out of the box.
Here is the project page and here is the mailing list.
Edit: maybe their documentation is lacking some keywords, but just to be clear: one or the purposes of ProtoRPC is to provide a solid foundation to create REST services.

Related

Flask Custom Login and Template Rendering

I am new to learning Python for web development and have decided to go with Flask as my framework of choice as of now. I have chosen this primarily for its bare-bones approach on web development and I want to make as much of my web app custom and on my own as possible. I have made a very basic MVC framework in PHP and would like to make something like this in Python. I was researching some ways to interact with a database and add user login/register support and my original thoughts were that I wanted to do this all custom with my own methods and objects and what not. Similar to how I have done in PHP, so I can learn as much about developing my own back-end efficiently for long term production projects. In some research I found the basic objects in Flask such as Login Manager, Login-Form and Flask-Admin, etc. I don't like the idea of using these nicely packaged things that I have very little control over and have not dev'd custom.
Using that kind of stuff I also feel that I am not learning how all of that stuff works on the lowest level so I could not reproduce some of the benefits they are giving me later on in life when project circumstances change and maximum flexibility, customization, maintainability, and efficiency is needed. Obviously I am not in that position right now, but I DO know how to write this back end stuff in PHP and am just wondering if that means anything as far as managing sessions and Authentication on my own in Python/Flask, or if my thinking is totally out of ocontext and its not even close to managing the same stuff.
It is a really great idea to learn how authentication works at a low level -- it's particularly important as many people never learn this stuff, and it's quite interesting!
What I'd recommend you do is take a look at the official Flask tutorial (http://flask.pocoo.org/docs/0.10/tutorial/), as it covers a lot of this (working directly with sessions, etc.).
What I would not recommend, however, is using this sort of thing in production.
Using your own authentication code is almost never a good idea -- it's much better to rely on a well supported library that has been audited by other people for security issues.
In the Flask world you've got a couple choices:
Flask-Login: https://flask-login.readthedocs.org/en/latest/
Flask-Security: https://pythonhosted.org/Flask-Security/
Flask-Stormpath: http://flask-stormpath.readthedocs.org/en/latest/
Of those 3, I really like Flask-Stormpath -- but I'm super biased as I wrote it =)
Flask-Stormpath supports the widest array of customization / etc., and allows you to do whatever you want with it.
Hope that helps!
Flask official doc have some app examples. One of them is MiniTwit a micro Twitter clone. As it is a complete app, you could found much of what you're looking for. If you want to make something greater, try Full Stack Python Flask tutorial

minimalistic python service layer

I plan to have mysql/postgres database along with a thin service layer which I basically would like to us to receive restful requests and return results in json format. I'd like to use python for latter. Since I am new to python frameworks, if I'd use any for this thin layer which one would that be? The more minimalistic (thinner) the better of course.
Thanks for sharing your experience.
Juergen
PS: If it dealt with authentication/auhorization that would be a bonus.
Flask is one of the python Microframework.
It support session.
very lean and easy to build new stuff.
http://flask.pocoo.org/
Pyramid (former name was Pylons) is also good candidate to build simple web service with RESTful.
Good thing about pyramid is you can expand it from very small scale to large scale easily.
pyramid also support authentication and session and bunch of template engine or ORM.
http://www.pylonsproject.org/
If u consider expanding your project later, I suggest using Pyramid.
For very simple things I am always using bottle. But if you need a little bit more than that (like auth), consider using web2py. It does all you need with very little coding.

Python frameworks for developing facebook apps

I'd like to ask you about your experiences in developing facebook applications in Python. Which of the popular web frameworks for this language you think best suits this purpose? I know "best" is a very subjective word, so I'm specifically interested in the following:
Most reusable libraries. For example one might want to automatically create accounts for new logged in facebook users, but at the same time provide an alternative username + password logging functionality. I need authentication to fit into this nicely.
Facebook applications tend to differ from CMS-like sites. They are action intensive. For more complicated use-cases, usually some kind of caching for the data fetched from Open Graph API is required in order to be able to perform some queries on local and facebook data at once (for example join some tables based on friendship relation).
I'd definitely prefer popular solutions. They just seem to be much more stable and better thought through. I've previously developed a facebook application in Grails and I as much as I liked the architecture and the general ideas, the amount of bugs and complication that I ran into was just a little bit too much. Also Groovy is still quite an exotic language to develop in, and this time I'm not going to work on my own.
I'm not new to Python, but definitely new to web development in Python. Though after the experience with Grails and all its twists and turns I doubt Python could really scare me.
I would almost undoubtedly go with Django as the easiest and most popular framework for developing any type of web applications, if there's a need for a full-stack framework.
Specifically, in regards to Django's app universe, it is plentiful with many active applications -- but that has its downfalls too. There's no standard application for any 'one' thing, but there are a few applications that will do basically 90% of all that's needed. Sometimes the code is poorly written, but most of the time, the apps work and do what they are needed to do, so there's almost no need for someone to dive right in to the code.
Narrowing down our options, I have had great luck with Omab's Django-Social-Auth, which was absolutely a snap to integrate. It required 3 variables in my settings.py and I was up and running.
The only issue might be if you do not want to use the django.contrib.auth.User model, but, if you are not thinking about using that, I would think about that decision twice :)
To narrow it down even further, pyfacebook is another option for integrating Facebook. It comes with a djangofb application so it's just drop, add to settings.py and all is well. It even comes with an example Django application as part of the distribution. I've had pretty good luck with this application, but, I still think Omab's much easier to integrate.
Finally, Facebook's own python-sdk is easy to integrate from a raw standpoint, where they just give you access to their APIs using a simple Python API. However, it seems to cater more to the AppEngine folks, so YMMV.
I've used Django for quite some time. As of late I use Jinja2 instead. No particular reason, but it's another option
If you do not want to start on Django now. Try learning Flask(which is comparatively a lot easier to begin than Django) and then start building app with Flask.

I'm learning python and am interested in using it for web-scripting. What frameworkes are out there and do I need one?

I've been learning python for use in ArcGIS and some other non-web applications. However, now that I've taken on building a personal website I am interested in using it for web development (as it is the only scripting language I currently know).
I've noticed that there are a lot of these things called "frameworks", such as Django. From what I understand they are just a collection of packages to save you from re-inventing the wheel but I don't really know how they work.
Furthermore, I do not like GUIs, if I need a framework I would like to find one that could be used through a terminal, starts out simple and can be scaled for more complexity when I'm ready. Any advice or ideas on frameworks and why I would want to use one?
The Python web frameworks have nothing to do with GUIs, and can all be used via the terminal.
The benefits of a framework, as you say, are all to do with making your life easier by supplying the components you need to build a website: the main ones are database interaction through an ORM, a templating system, and URL routing. On top of that, the big frameworks also included optional extras like user authentication, administration interface, and so on.
Personally I like Django, but your mileage may vary: I would say, though, that whatever you do with Python and the web will require some sort of framework, even if it's one of the absolute minimal ones like Flask which basically do just the routing part. There's simply no point in writing all this stuff from scratch when it's been done for you.
I'd second the post above: Django is a great framework and will save you loads of time in the long run.
Pretty much every challenge you'll come across when writing a web application will already have been solved, e.g. How do I send emails? What about an admin interface to edit the data? User security?
In my view picking the best framework is all about the ecosystem around that framework. How well used is it? Is it discussed widely on the internet? Have others encountered, and solved, the problems I'm facing?
In terms of where you start, see the Django Tutorial here:
http://docs.djangoproject.com/en/1.2/intro/tutorial01/
If you think Django offers you too much, I'd recommend that you take a look at CherryPy just to compare the different, and much simpler, approach.
With Python, you've got lots of options. To start, I would recommend looking here -- it explains the basics and provides a fairly complete list of frameworks.
If you're looking for something that starts out simple but can also handle more complexity, then you should take a look at web2py. It requires no installation or configuration, has no dependencies, and includes a web server and a relational database. It also includes an optional web-based integrated development environment and admin interface, but you can work through the terminal instead if you prefer.
It's very easy to learn and was designed for ease of use, faster development, and security. You can get a lot done with very little code thanks to the included scaffolding app along with many sensible default behaviors. As things get more complex, web2py can handle it, as it is a well-integrated full-stack framework with lots of built-in functionality, including a database abstraction layer, form handling and validation, access control, web services, and easy Ajax integration.
Personnally, I don't use any framework, I write either from scratch on BaseHTTPServer, or using WSGI (with mod_wsgi).
It is a bit long to write the skeleton, but I think it is faster (I mean at runtime), there is less constraints, and there is lesser to learn.

Python for web scripting

I'm just starting out with Python and have practiced so far in the IDLE interface. Now I'd like to configure Python with MAMP so I can start creating really basic webapps — using Python inside HTML, or well, vice-versa. (I'm assuming HTML is allowed in Python, just like PHP? If not, are there any modules/template engines for that?)
What modules do I need to install to run .py from my localhost? Googling a bit, it seems there're various methods — mod_python, FastCGI etc.. which one should I use and how to install it with MAMP Pro 1.8.2?
Many thanks
I think probably the easiest way for you to get started is to work with something like Django. It's a top-to-bottom web development stack which provides you with everything you need to develop and run a backend server. Things can be very simple in that world, no need to mess around with mod_python or FastCGI unless you really have the need.
It's also nice because it conforms to WSGI, which is a Python standard which allows you to plug together unrelated bits of reusable code to add specific functionality to your web app when needed (say for example on-the-fly gzip compression, or OpenID authentication). Once you have outgrown the default Django stack, or want to change something specific you can go down this road if you want.
Those are a few pointers to get you started. You could also look at other alternative frameworks such as TurboGears or paste if you wanted but Django is a great way to get something up and running quickly. Anyway, I'm sure you'll enjoy the experience: WSGI makes it a real joy knocking up web apps with the wealth of Python code you'll find on the web.
[edit: you may find it helpful to browse some of the may Django related questions here on stack-overflow if you run into problems]
You asked whether HTML is allowed within Python, which indicates that you still think too much in PHP terms about it. Contrary to PHP, Python was not designed to create dynamic web-pages. Instead, it was designed as a stand-alone, general-purpose programming language. Therefore you will not be able to put HTML into Python. There are some templating libraries which allow you to go the other way around, somewhat, but that's a completely different issue.
With things like Django or TurboGears or all the other web-frameworks, you essentially set up a small, stand-alone web-server (which comes bundled with the framework so you don't have to do anything), tell the server which function should handle what URL and then write those functions. In the simplest case, each URL you specify has its own function.
That 'handler function' (or 'view function' in Django terminology) receives a request object in which interesting info about the just-received request is contained. It then does whatever processing is required (a DB query for example). Finally, it produces some output, which is returned to the client. A typical way to get the output is to have some data passed to a template where it is rendered together with some HTML.
So, the HTML is separated in a template (in the typical case) and is not in the Python code.
About Python 3: I think you will find that the vast majority of all Python development going on in the world is still with Python 2.*. As others have pointed out here, Python 3 is just coming out, most of the good stuff is not available for it yet, and you shouldn't be bothered about that.
My advise: Grab yourself Python 2.6 and Django 1.1 and dive in. It's fun.
Django is definitely not the easiest way.
check out pylons. http://pylonshq.com/
also check sqlalchemy for sql related stuff. Very cool library.
On the other hand, you can always start with something very simple like mako for templating. http://www.makotemplates.org/

Categories

Resources