Skip to main content

SimpleAPI is a Python package for making application programm interface. Everyone can make the API methods just like the Django Models.

Project description

SimpleAPI is a Python package for making application programm interface. Everyone can make the API methods just like the Django Models.

Github repo

Installation

Install using pip:

pip install simple_api

…or clone the project from github:

https://github.com/san4ezy/simple_api.git
  1. Add simple_api application to INSTALLED_APPS settings:

    INSTALLED_APPS = (
        ...
        'simple_api',
    )
    
  2. Import package to “urls.py” and connect SimpleAPI to your project:

    import simple_api
    simple_api.connect()
    
  3. Add the SimpleAPI pattern to your urlpatterns:

    url(r'api/', include(simple_api.urls)),
    
  4. Make file with name api_models.py into your application, import the SimpleAPI package and make custom classes for your API

Example

Let’s take a look at a quick example how to use SimpleAPI.

We’ll create some classes, which makes methods for your project`s API using SimpleAPI.

Let`s edit “api_models.py”:

import simple_api
from main.models import *

# This class makes a url http://your-domain/api/getprojects/
class GetProjects(simple_api.SimpleAPI):
    filter = simple_api.CharVariable(blank=True, default='active', choices=['all', 'active', 'not_active', ])
    mode = simple_api.CharVariable(blank=True, default='object', choices=['object', 'name', ])
    description = u"Getting projects data"

    def method(self):
        queryset = None
        if self.filter.case(0):
            queryset = Project.objects.all()
        elif self.filter.case(1):
            queryset = Project.objects.filter(active=True)
        elif self.filter.case(2):
            queryset = Project.objects.filter(active=False)
        if self.mode.case(0):
            return queryset
        elif self.mode.case(1):
            return [(x.pk, x.name, ) for x in queryset]

# This class makes a url: http://your-domain/api/projects__<method>/ , where "method" should be "get", "make", "edit" or "delete".
class Projects(simple_api.ModelAPI):
    model = Project

Project details


Release history Release notifications

This version
History Node

0.2.1

History Node

0.2.0

History Node

0.1.9

History Node

0.1.8

History Node

0.1.7-2

History Node

0.1.7-1

History Node

0.1.7

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
simple_api-0.2.1.tar.gz (6.2 kB) Copy SHA256 hash SHA256 Source None Jun 22, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page