Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install django-formapi

How to install django-formapi

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install django-formapi
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.0.7 Available View build log
Windows (64-bit)
0.0.7 Available View build log
Mac OS X (10.5+)
0.0.7 Available View build log
Linux (32-bit)
0.0.7 Available View build log
Linux (64-bit)
0.0.7 Available View build log
Lastest release
version 0.0.7 on Jun 26th, 2013

Create JSON API:s with HMAC authentication and Django form-validation.



Install django-formapi in your python environment

System Message: ERROR/3 (<string>, line 15)

Unknown directive type "code".

.. code:: sh

    $ pip install django-formapi

Add formapi to your INSTALLED_APPS setting.

System Message: ERROR/3 (<string>, line 21)

Unknown directive type "code".

.. code:: python


Add formapi.urls to your urls.py.

System Message: ERROR/3 (<string>, line 30)

Unknown directive type "code".

.. code:: python

  urlpatterns = patterns('',
      url(r'^api/', include('formapi.urls')),


Go ahead and create a calls.py.

System Message: ERROR/3 (<string>, line 42)

Unknown directive type "code".

.. code:: python

  class DivisionCall(calls.APICall):
      Returns the quotient of two integers
      dividend = forms.FloatField()
      divisor = forms.FloatField()

      def action(self, test):
          dividend = self.cleaned_data.get('dividend')
          divisor = self.cleaned_data.get('divisor')
          return dividend / divisor

  API.register(DivisionCall, 'math', 'divide', version='v1.0.0')

Just create a class like your regular Django Forms but inheriting from APICall. Define the fields that your API-call should receive. The action method is called when your fields have been validated and what is returned will be JSON-encoded as a response to the API-caller. The API.register call takes your APICall-class as first argument, the second argument is the namespace the API-call should reside in, the third argument is the name of your call and the fourth the version. This will result in an url in the form of api/[version]/[namespace]/[call_name]/ so we would get /api/v1.0.0/math/divide/.

A valid call with the parameters {'dividend': 5, 'divisor': 2} would result in this response:

System Message: ERROR/3 (<string>, line 67)

Unknown directive type "code".

.. code:: javascript

  {"errors": {}, "data": 5, "success": true}

An invalid call with the parameters {'dividend': "five", 'divisor': 2} would result in this response:

System Message: ERROR/3 (<string>, line 73)

Unknown directive type "code".

.. code:: javascript

  {"errors": {"dividend": ["Enter a number."]}, "data": false, "success": false}


By default APICalls have HMAC-authentication turned on. Disable it by setting signed_requests = False on your APICall.

If not disabled users of the API will have to sign their calls. To do this they need a secret generate, create a APIKey through the django admin interface. On save a personal secret and key will be generated for the API-user.

To build a call signature for the DivisonCall create a querystring of the calls parameters sorted by the keys dividend=5&divisor=2. Create a HMAC using SHA1 hash function. Example in python:

System Message: ERROR/3 (<string>, line 88)

Unknown directive type "code".

.. code:: python

  import hmac
  from hashlib import sha1
  hmac_sign = hmac.new(secret, urllib2.quote('dividend=5&divisor=2'), sha1).hexdigest()

A signed request against DivisionCall would have the parameters {'dividend': 5, 'divisor': 2, 'key': generated_key, 'sign': hmac_sign}


Visit /api/discover for a brief documentation of the registered API-calls.

Subscribe to package updates

Last updated Jun 26th, 2013

Download Stats

Last month:4

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.