skip to navigation
skip to content

Not Logged In

stagecoach-apy 1.0.12

Python RESTful API Framework

apy

https://travis-ci.org/stagecoachio/apy.png?branch=master Downloads Latest Version

apy is a powerful Python framework designed with a clear and single purpose: To serve as a REST API. So, apy do one thing and do it well.

Most existing Python Frameworks are extremely verbose and cumbersome for a Python coders who need a simple and elegant toolkit to create full-featured API REST applications.

They can provide most of the API REST capabilities that you should need, but because they are multipropose, you are overarchitecturing your API REST application, and requires an extra amount of work to perform the simplest of tasks. So, when you uses a multipropose framework, you might been not following the python principle "Simple is better than complex.".

Things shouldn't be this way. Not in Python.

apy has an exceptional performance, because uses the Tornado asynchronous networking library. Powered by Facebook.

By using non-blocking network I/O, can scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user.


We believe development must be an enjoyable and creative experience to be truly fulfilling.

Happy developers make the best code.


apy is open-sourced software licensed under the MIT license


Run server:

from apy.server import run_server

config_dir = 'config'
settings_file_path = 'settings.yml'
run_server(config_dir, settings_file_path)

The configuration files should be in the config_dir path. (relative paths are relative to your server runner file)

Also, you can specify absolute paths for .yml configs.


Optional configuration parameters:

  • max_concurrent_request

Usage examples:

max_concurrent_requests: 5
max_concurrent_requests: -1 # No limit

Note: this is an optional parameter, so if you don't set this parameter, no limit is setted by default.

  • debug (show extra info on console)

Usage examples:

debug: yes
debug: no

Note: this is an optional parameter, so if you don't set this parameter, the debug is disabled.

App Config files:

The app config files are in yaml format.


settings.yml

Example:

port: 80
routes: routes.yml

Note: the port parameter is optional, by default is 80


routes.yml

Example:

hello:
    path:       /foo/bar/{name}/{surname}
    method:     GET
    controller: myapplication.controllers.foo.Foo

world:
    path:       /something/{phone}
    methods:    POST, GET
    controller: myapplication.controllers.bar.Foo
    action:     something_action
    requirements:
        - phone: \d+
    host:       (wwww|foo).something.com
    protocols:  [http, https]

Only the path, method (or methods) and the controller options are required, the another are optional.

By default the route matchs with the action() method of the specified controller, the default requirments and host accepts any string, and finally, the default protocols are http and https.

Dispatching Requests into Controllers

When the Dispatcher matches any request with a route, the controller is instantiated, and the request object will be auto injected. then, the action method of these controller will be called, getting the variable path parameters if exist.

Example:

  • route path: /foo/{name}/{city}
  • request path: /foo/Felix/Barcelona
from apy.application import Controller


class SomethingController(Controller):
    def action(self, name, city)
        user_info = "Name: %s. City: %s" % (name, city)  # Name: Felix. City: Barcelona

Response

In the action method of your controller, you should instantiate a Response Object (JsonResponse, MsgpackResponse, etc) and set the desired content data/status and then return this Response object.

Example:

response = JsonResponse()
response.data = {'foo': 'bar'}
response.set_status(200, 'optional custom message')  # by default the response status is 200 and the status text can be autofilled
return response

Changelog

 
File Type Py Version Uploaded on Size
stagecoach-apy-1.0.12.tar.gz (md5) Source 2014-03-29 39KB
  • Downloads (All Versions):
  • 4 downloads in the last day
  • 53 downloads in the last week
  • 631 downloads in the last month