Skip to main content
What is it?
============
a python jsend module.
compatable with jsend: http://labs.omniti.com/labs/jsend


Note:
============
(note: if there is a "README.rst" file, it's a softlink of "README")

Install:
============
pip install python-jsend

Or download the tarbal, decompress it, then run "python setup.py install"

Test:
==========
python setup.py test
note: it may show the warning messages like something below:

"test.pytest.py/_pytest.core:147: UserWarning: Module _pytest was already imported from test.pytest.py/_pytest, but /usr/local/lib/python2.6/dist-packages is being added to sys.path"

It does no harm, just ommit it.


Shortely: (borrowed from http://labs.omniti.com/labs/jsend)
=================================================================
"""
A basic JSend-compliant response is as simple as this:
{{{
{
status : "success",
data : {
"post" : { "id" : 1, "title" : "A blog post", "body" : "Some useful content" }
}
}
}}}

When setting up a JSON API, you'll have all kinds of different types of calls and responses. JSend separates responses into some basic types, and defines required and optional keys for each type:

||''Type''||''Description''||''Required Keys''||''Optional Keys''||
||success ||All went well, and (usually) some data was returned.||status, data||||
||fail ||There was a problem with the data submitted, or some pre-condition of the API call wasn't satisfied||status, data||||
||error ||An error occurred in processing the request, i.e. an exception was thrown||status, message||code, data||



| ''Type'' | ''Description'' | ''Required Keys'' | ''Optional Keys'' |
|----------+--------------------------------------------------------+-------------------+-------------------|
| success | All went well, and (usually) some data was returned. | status, data | |
| | | | |
| fail | There was a problem with the data submitted, | status, data | |
| | or some pre-condition of the API call wasn't satisfied | | |
| | | | |
| error | An error occurred in processing the request, | status, message | code, data |
| | i.e. an exception was thrown | | |

"""


changelog: (2012-07-16)
In pracmatical usage, code representing status is very import, so add 'code' key to "Required Keys"


| ''Type'' | ''Description'' | ''Required Keys'' | ''Optional Keys'' |
|----------+--------------------------------------------------------+--------------------+-------------------|
| success | All went well, and (usually) some data was returned. | status, code, data | |
| | | | |
| fail | There was a problem with the data submitted, | status, code, data | |
| | or some pre-condition of the API call wasn't satisfied | | |
| | | | |
| error | An error occurred in processing the request, | status, message | code, data |
| | i.e. an exception was thrown | | |


changelog: (2012-07-26)
In pracmatical usage, a key "message" for all responese is very convenient for development.
So add 'message' key to "Optional Keys" for type(success, fail)


| ''Type'' | ''Description'' | ''Required Keys'' | ''Optional Keys'' |
|----------+--------------------------------------------------------+--------------------+-------------------|
| success | All went well, and (usually) some data was returned. | status, code, data | message |
| | | | |
| fail | There was a problem with the data submitted, | status, code, data | message |
| | or some pre-condition of the API call wasn't satisfied | | |
| | | | |
| error | An error occurred in processing the request, | status, message | code, data |
| | i.e. an exception was thrown | | |




This module includes 3 classes:
==============================
RSuccess --> Result Success

RFail --> Result Fail

RError --> Result Error


Usage: (sample)
========================


In [1]: from jsend import RSuccess, RFail, RError # from jsend import *

In [2]: rs = RSuccess()

In [3]: rs
Out[3]: {'data': {}, 'status': 'success'}

In [4]: rs.data['post'] = {'username' : 'you', 'password' : 'pwd' }

In [5]: rs
Out[5]: {'data': {'post': {'password': 'pwd', 'username': 'you'}}, 'status': 'success'}

In [6]: rf = RFail()

In [7]: rf
Out[7]: {'data': {}, 'status': 'fail'}

In [8]: rf.data['why'] = 'You have entered the wrong number'

In [9]: rf
Out[9]: {'data': {'why': 'You have entered the wrong number'}, 'status': 'fail'}

In [10]: rr = RError

In [11]: rr
Out[11]: jsend.jsend.RError

In [12]: rr = RError()

In [13]: rr
Out[13]:
{'code': {},
'data': {},
'message': 'error occurres during processing',
'status': 'error'}

In [14]: rr.data['stack'] = 'stack overflows'

In [15]: rr.code['return_code'] = 1

In [16]: rr
Out[16]:
{'code': {'return_code': 1},
'data': {'stack': 'stack overflows'},
'message': 'error occurres during processing',
'status': 'error'}

Metadata

Release files for python-jsend 0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-jsend 0.5
File Size Uploaded
python-jsend-0.5.tar.gz 145.0 kB Details

Release files / python-jsend-0.5.tar.gz

Download URL python-jsend-0.5.tar.gz
Size 145.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0dc6d1349030d4ae5dd78e25ce0cfdfe0c161511dbc8e33f820f50d4e52404af
BLAKE2b-256 checksum
How to use checksums
0515a2674467516cfd55acfc760a88b9c745341235f5ad8a85f2a26b492f298f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.9.2

1 release file

0.7.1

1 release file

0.7

1 release file

0.6

1 release file

0.5.1

1 release file

This release

0.5 This release

1 release file

0.4.1

1 release file

0.3

1 release file

0.2.4

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.7

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page