What Python framework for a REST/JSON web service with no front end?
Asked Answered
T

6

33

I need to create a Python REST/JSON web service for an iOS app to interact with. There will be no front end on the web.

What will be the fastest, most lightweight framework to use for this? Learning curve to implement also considered?

From the research I've done Django-Tastypie or Djanjo-Piston look like the best options, with Tastypie winning because the codebase is being maintained actively?

Theotheobald answered 30/10, 2011 at 4:58 Comment(1)
possible duplicate of Recommendations of Python REST (web services) framework?Format
P
13

In general, I think you'll find web2py to be one of the easiest frameworks to set up, learn, and use. web2py makes it very easy to generate JSON (just add a .json extension), and it now includes new functionality to automatically create RESTful web services to access database models. In particular, check out the parse_as_rest and smart_query functionality.

If you need any help, ask on the mailing list.

Pacification answered 30/10, 2011 at 22:57 Comment(0)
W
25

At Pycon Australia, Richard Jones compared the most popular lightweight web frameworks. Bottle came out on top. Here is the full presentation.

Winzler answered 30/10, 2011 at 6:1 Comment(0)
P
13

In general, I think you'll find web2py to be one of the easiest frameworks to set up, learn, and use. web2py makes it very easy to generate JSON (just add a .json extension), and it now includes new functionality to automatically create RESTful web services to access database models. In particular, check out the parse_as_rest and smart_query functionality.

If you need any help, ask on the mailing list.

Pacification answered 30/10, 2011 at 22:57 Comment(0)
A
6

When it comes to lightweight, CherryPy is pretty up there.

import cherrypy

class HelloWorld(object):
    def index(self):
        return "Hello World!"
    index.exposed = True

cherrypy.quickstart(HelloWorld())
Alaric answered 30/10, 2011 at 5:1 Comment(1)
Not to mention, @tools.json_in() and @tools.json_out() in recent versions.Chalky
A
2

If I were you I would use web.py that is really convenient to do that kind of rapid prototyping of lightweight REST applications. Check out this snippet from the home page:

import web

urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:        
    def GET(self, name):
        if not name: 
            name = 'World'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()
Axinomancy answered 30/10, 2011 at 4:59 Comment(0)
N
1

Take a look to flask and its extension flask-restful

from flask import Flask
from flask.ext import restful

app = Flask(__name__)
api = restful.Api(app)

class HelloWorld(restful.Resource):
    def get(self):
        return {'hello': 'world'}

api.add_resource(HelloWorld, '/')

if __name__ == '__main__':
    app.run(debug=True)
Nelrsa answered 4/2, 2015 at 16:45 Comment(0)
R
0

You might also want to check out Parse. They are free to use right now, and will give you a nice REST API for you mobile apps.

However, as @iksnar points out, you don't write anything in Python, or anything at all for the backend. If you need to have the backend running in Python on your own servers I am a big fan of TastyPie if you are using Django already and the Django ORM already.

Roundtheclock answered 30/11, 2011 at 1:28 Comment(3)
In fact, it'll be even easier since they have native SDKs for iOS. You don't even need to know how to use a REST API and handle JSON encoding/decoding etc. You just work with native objects and save them to the platform.Quetzal
the topic is specific to a Python framework. Parse does not support use of Python. In fact, if you want anything server side logic beyond CRUD functions, you will need to write in Java.Loidaloin
Parse is also discontinued now. FB shut it down.Neuman

© 2022 - 2024 — McMap. All rights reserved.