



  

jsonrpc 1.11.1 documentation

 [jsonrpc](index.html#document-index) 

 stable

 

* [Quickstart](index.html#document-quickstart)

	+ [Installation](index.html#installation)

	+ [Integration](index.html#integration)

* [Method dispatcher](index.html#document-dispatcher)

* [Exceptions](index.html#document-exceptions)

	+ [JSON-RPC Errors](index.html#json-rpc-errors)

	+ [JSON-RPC Exceptions](index.html#json-rpc-exceptions)

* [Integration with Django](index.html#document-django_integration)

	+ [Create api instance](index.html#create-api-instance)

	+ [Add api urls to the project](index.html#add-api-urls-to-the-project)

	+ [Add methods to api](index.html#add-methods-to-api)

	+ [Make requests to api](index.html#make-requests-to-api)

* [Integration with Flask](index.html#document-flask_integration)

	+ [Create api instance](index.html#create-api-instance)

	+ [Add api endpoint to the project](index.html#add-api-endpoint-to-the-project)

	+ [Add methods to api](index.html#add-methods-to-api)

	+ [Make requests to api](index.html#make-requests-to-api)

* [jsonrpc Package](index.html#document-jsonrpc)

	+ [JSONRPC](index.html#module-jsonrpc.jsonrpc)

	+ [Exceptions](index.html#module-jsonrpc.exceptions)

	+ [Manager](index.html#module-jsonrpc.manager)

	+ [jsonrpc.backend.django module](index.html#jsonrpc-backend-django-module)

[jsonrpc](index.html#document-index)

* [Docs](index.html#document-index) »

* jsonrpc 1.11.1 documentation

* [Edit on GitHub](https://github.com/pavlov99/json-rpc/blob/f1b4e5e96661efd4026cb6143dc3acd75c6c4682/docs/source/index.rst)

---

JSON-RPC transport implementation[¶](#json-rpc-transport-implementation "Permalink to this headline")

=====================================================================================================

| Source code: | <https://github.com/pavlov99/json-rpc> |

| Issue tracker: | <https://github.com/pavlov99/json-rpc/issues> |

JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. Primarily this specification defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over http, or in many various message passing environments. It uses JSON (RFC 4627) as data format.

Features[¶](#features "Permalink to this headline")

---------------------------------------------------

* Supports [JSON-RPC2.0](http://www.jsonrpc.org/specification) and [JSON-RPC1.0](http://json-rpc.org/wiki/specification)

* Implementation is complete and 100% tested

* Does not depend on transport realisation, no external dependencies

* It comes with request manager and optional Django support

* Compatible with Python 2.6, 2.7, 3.x >= 3.2, PyPy

Contents[¶](#contents "Permalink to this headline")

---------------------------------------------------

### Quickstart[¶](#quickstart "Permalink to this headline")

#### Installation[¶](#installation "Permalink to this headline")

| Requirements: | **Python 2.6, 2.7**, **Python 3.x >= 3.2** or **PyPy** |

To install the latest released version of package:

```

pip install json-rpc

```

#### Integration[¶](#integration "Permalink to this headline")

Package is transport agnostic, integration depends on you framework. As an example we have server with [Werkzeug](http://werkzeug.pocoo.org/) and client with [requests](http://www.python-requests.org/en/latest/).

Server

```

from werkzeug.wrappers import Request, Response

from werkzeug.serving import run\_simple

from jsonrpc import JSONRPCResponseManager, dispatcher

@dispatcher.add\_method

def foobar(\*\*kwargs):

    return kwargs["foo"] + kwargs["bar"]

@Request.application

def application(request):

    # Dispatcher is dictionary {<method\_name>: callable}

    dispatcher["echo"] = lambda s: s

    dispatcher["add"] = lambda a, b: a + b

    response = JSONRPCResponseManager.handle(

        request.data, dispatcher)

    return Response(response.json, mimetype='application/json')

if \_\_name\_\_ == '\_\_main\_\_':

    run\_simple('localhost', 4000, application)

```

Client

```

import requests

import json

def main():

    url = "http://localhost:4000/jsonrpc"

    headers = {'content-type': 'application/json'}

    # Example echo method

    payload = {

        "method": "echo",

        "params": ["echome!"],

        "jsonrpc": "2.0",

        "id": 0,

    }

    response = requests.post(

        url, data=json.dumps(payload), headers=headers).json()

    assert response["result"] == "echome!"

    assert response["jsonrpc"]

    assert response["id"] == 0

if \_\_name\_\_ == "\_\_main\_\_":

    main()

```

Package ensures that request and response messages have correct format.

Besides that it provides [`jsonrpc.manager.JSONRPCResponseManager`](index.html#jsonrpc.manager.JSONRPCResponseManager "jsonrpc.manager.JSONRPCResponseManager") which handles server common cases, such as incorrect message format or invalid method parameters.

Futher topics describe how to add methods to manager, how to handle custom exceptions and optional Django integration.

### Method dispatcher[¶](#module-jsonrpc.dispatcher "Permalink to this headline")

Dispatcher is used to add methods (functions) to the server.

For usage examples see [`Dispatcher.add\_method()`](#jsonrpc.dispatcher.Dispatcher.add_method "jsonrpc.dispatcher.Dispatcher.add_method")

*class* `jsonrpc.dispatcher.``Dispatcher`(*prototype=None*)[[source]](_modules/jsonrpc/dispatcher.html#Dispatcher)[¶](#jsonrpc.dispatcher.Dispatcher "Permalink to this definition")

Dictionary like object which maps method\_name to method.

`__init__`(*prototype=None*)[[source]](_modules/jsonrpc/dispatcher.html#Dispatcher.__init__)[¶](#jsonrpc.dispatcher.Dispatcher.__init__ "Permalink to this definition")

Build method dispatcher.

| Parameters: | **prototype** (*object* *or* *dict**,* *optional*) – Initial method mapping. |

Examples

Init object with method dictionary.

```

>>> Dispatcher({"sum": lambda a, b: a + b})

None

```

`add_method`(*f*, *name=None*)[[source]](_modules/jsonrpc/dispatcher.html#Dispatcher.add_method)[¶](#jsonrpc.dispatcher.Dispatcher.add_method "Permalink to this definition")

Add a method to the dispatcher.

| Parameters: | * **f** (*callable*) – Callable to be added.

* **name** (*str**,* *optional*) – Name to register (the default is function **f** name)

 |

Notes

When used as a decorator keeps callable object unmodified.

Examples

Use as method

```

>>> d = Dispatcher()

>>> d.add_method(lambda a, b: a + b, name="sum")

<function __main__.<lambda>>

```

Or use as decorator

```

>>> d = Dispatcher()

>>> @d.add_method

    def mymethod(*args, **kwargs):

        print(args, kwargs)

```

`build_method_map`(*prototype*, *prefix=''*)[[source]](_modules/jsonrpc/dispatcher.html#Dispatcher.build_method_map)[¶](#jsonrpc.dispatcher.Dispatcher.build_method_map "Permalink to this definition")

Add prototype methods to the dispatcher.

| Parameters: | * **prototype** (*object* *or* *dict*) – Initial method mapping.

If given prototype is a dictionary then all callable objects will

be added to dispatcher.

If given prototype is an object then all public methods will

be used.

* **prefix** (*string**,* *optional*) – Prefix of methods

 |

### Exceptions[¶](#exceptions "Permalink to this headline")

According to specification, error code should be in response message. Http

server should respond with status code 200, even if there is an error.

#### JSON-RPC Errors[¶](#json-rpc-errors "Permalink to this headline")

Note

Error is an object which represent any kind of erros in JSON-RPC specification. It is not python Exception and could not be raised.

Errors (Error messages) are members of [`JSONRPCError`](index.html#jsonrpc.exceptions.JSONRPCError "jsonrpc.exceptions.JSONRPCError") class. Any custom error messages should be inherited from it.

The class is responsible for specification following and creates response string based on error’s attributes.

JSON-RPC has several predefined errors, each of them has reserved code, which should not be used for custom errors.

| Code | Message | Meaning |

| -32700 | Parse error | Invalid JSON was received by the server.An error occurred on the server while parsing the JSON text. |

| -32600 | Invalid Request | The JSON sent is not a valid Request object. |

| -32601 | Method not found | The method does not exist / is not available. |

| -32602 | Invalid params | Invalid method parameter(s). |

| -32603 | Internal error | Internal JSON-RPC error. |

| -32000 to -32099 | Server error | Reserved for implementation-defined server-errors. |

[`JSONRPCResponseManager`](index.html#jsonrpc.manager.JSONRPCResponseManager "jsonrpc.manager.JSONRPCResponseManager") handles common errors. If you do not plan to implement own manager, you do not need to write custom errors. To controll error messages and codes, json-rpc has exceptions, covered in next paragraph.

#### JSON-RPC Exceptions[¶](#json-rpc-exceptions "Permalink to this headline")

Note

Exception here a json-rpc library object and not related to specification. They are inherited from python Exception and could be raised.

JSON-RPC manager handles dispatcher method’s exceptions, anything you raise would be catched.

There are two ways to generate error message in manager:

First is to simply raise exception in your method. Manager will catch it and return [`JSONRPCServerError`](index.html#jsonrpc.exceptions.JSONRPCServerError "jsonrpc.exceptions.JSONRPCServerError") message with description. Advantage of this mehtod is that everything is already implemented, just add method to dispatcher and manager will do the job.

If you need custom message code or error management, you might need to raise exception, inherited from [`JSONRPCDispatchException`](index.html#jsonrpc.exceptions.JSONRPCDispatchException "jsonrpc.exceptions.JSONRPCDispatchException"). Make sure, your exception class has error code.

New in version 1.9.0: Fix Invalid params error false generated if method raises TypeError. Now in this case manager introspects the code and returns proper exception.

### Integration with Django[¶](#integration-with-django "Permalink to this headline")

Note

Django backend is optionaly supported. Library itself does not depend on Django.

Django integration is similar project to project. Starting from version 1.8.4 json-rpc support it and provides convenient way of integration. To add json-rpc to Django project follow steps.

#### Create api instance[¶](#create-api-instance "Permalink to this headline")

If you want to use default (global) object, skip this step. In most cases it is enougth to start with it, even if you plan to add another version later. Default api is located here:

```

from jsonrpc.backend.django import api

```

If you would like to use different api versions (not, you could name methods differently) or use cudtom dispatcher, use

```

from jsonrpc.backend.django import JSONRPCAPI

api = JSONRPCAPI(dispatcher=<my\_dispatcher>)

```

Later on we assume that you use default api instance

#### Add api urls to the project[¶](#add-api-urls-to-the-project "Permalink to this headline")

In your urls.py file add

```

urlpatterns = patterns(

    ...

    url(r'^api/jsonrpc/', include(api.urls)),

)

```

#### Add methods to api[¶](#add-methods-to-api "Permalink to this headline")

```

@api.dispatcher.add\_method

def my\_method(request, \*args, \*\*kwargs):

    return args, kwargs

```

Note

first argument of each method should be request. In this case it is possible to get user and control access to data

#### Make requests to api[¶](#make-requests-to-api "Permalink to this headline")

To use api, send POST request to api address. Make sure your message has correct format.

Also json-rpc generates method’s map. It is available at <api\_url>/map url.

### Integration with Flask[¶](#integration-with-flask "Permalink to this headline")

Note

Flask backend is optionaly supported. Library itself does not depend on Flask.

#### Create api instance[¶](#create-api-instance "Permalink to this headline")

If you want to use default (global) object, skip this step. In most cases it is enough to start with it, even if you plan to add another version later. Default api is located here:

```

from jsonrpc.backend.flask import api

```

If you would like to use different api versions (not, you could name methods differently) or use custom dispatcher, use

```

from jsonrpc.backend.flask import JSONRPCAPI

api = JSONRPCAPI(dispatcher=<my\_dispatcher>)

```

Later on we assume that you use default api instance.

#### Add api endpoint to the project[¶](#add-api-endpoint-to-the-project "Permalink to this headline")

You have to options to add new endpoint to your Flask application.

First - register as a blueprint. In this case, as small bonus, you got a /map handler, which prints all registered methods.

```

from flask import Flask

from jsonrpc.backend.flask import api

app = Flask(\_\_name\_\_)

app.register\_blueprint(api.as\_blueprint())

```

Second - register as a usual view.

```

from flask import Flask

from jsonrpc.backend.flask import api

app = Flask(\_\_name\_\_)

app.add\_url\_rule('/', 'api', api.as\_view(), methods=['POST'])

```

#### Add methods to api[¶](#add-methods-to-api "Permalink to this headline")

```

@api.dispatcher.add\_method

def my\_method(\*args, \*\*kwargs):

    return args, kwargs

```

#### Make requests to api[¶](#make-requests-to-api "Permalink to this headline")

To use api, send POST request to api address. Make sure your message has correct format.

### jsonrpc Package[¶](#jsonrpc-package "Permalink to this headline")

#### JSONRPC[¶](#module-jsonrpc.jsonrpc "Permalink to this headline")

JSON-RPC wrappers for version 1.0 and 2.0.

Objects diring init operation try to choose JSON-RPC 2.0 and in case of error

JSON-RPC 1.0.

from\_json methods could decide what format is it by presence of ‘jsonrpc’

attribute.

*class* `jsonrpc.jsonrpc.``JSONRPCRequest`[[source]](_modules/jsonrpc/jsonrpc.html#JSONRPCRequest)[¶](#jsonrpc.jsonrpc.JSONRPCRequest "Permalink to this definition")

Bases: `jsonrpc.utils.JSONSerializable`

JSONRPC Request.

*classmethod* `from_data`(*data*)[[source]](_modules/jsonrpc/jsonrpc.html#JSONRPCRequest.from_data)[¶](#jsonrpc.jsonrpc.JSONRPCRequest.from_data "Permalink to this definition")

*classmethod* `from_json`(*json\_str*)[[source]](_modules/jsonrpc/jsonrpc.html#JSONRPCRequest.from_json)[¶](#jsonrpc.jsonrpc.JSONRPCRequest.from_json "Permalink to this definition")

#### Exceptions[¶](#module-jsonrpc.exceptions "Permalink to this headline")

JSON-RPC Exceptions.

*exception* `jsonrpc.exceptions.``JSONRPCDispatchException`(*code=None*, *message=None*, *data=None*, *\*args*, *\*\*kwargs*)[[source]](_modules/jsonrpc/exceptions.html#JSONRPCDispatchException)[¶](#jsonrpc.exceptions.JSONRPCDispatchException "Permalink to this definition")

Bases: [`jsonrpc.exceptions.JSONRPCException`](#jsonrpc.exceptions.JSONRPCException "jsonrpc.exceptions.JSONRPCException")

JSON-RPC Dispatch Exception.

Should be thrown in dispatch methods.

*class* `jsonrpc.exceptions.``JSONRPCError`(*code=None*, *message=None*, *data=None*)[[source]](_modules/jsonrpc/exceptions.html#JSONRPCError)[¶](#jsonrpc.exceptions.JSONRPCError "Permalink to this definition")

Bases: `object`

Error for JSON-RPC communication.

When a rpc call encounters an error, the Response Object MUST contain the

error member with a value that is a Object with the following members:

| Parameters: | * **code** (*int*) – A Number that indicates the error type that occurred.

This MUST be an integer.

The error codes from and including -32768 to -32000 are reserved for

pre-defined errors. Any code within this range, but not defined

explicitly below is reserved for future use. The error codes are nearly

the same as those suggested for XML-RPC at the following

url: <http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php>

* **message** (*str*) – A String providing a short description of the error.

The message SHOULD be limited to a concise single sentence.

* **data** (*int* *or* *str* *or* *dict* *or* *list**,* *optional*) – A Primitive or Structured value that contains additional

information about the error.

This may be omitted.

The value of this member is defined by the Server (e.g. detailed error

information, nested errors etc.).

 |

`code`[¶](#jsonrpc.exceptions.JSONRPCError.code "Permalink to this definition")

`data`[¶](#jsonrpc.exceptions.JSONRPCError.data "Permalink to this definition")

*static* `deserialize`(*s*, *encoding=None*, *cls=None*, *object\_hook=None*, *parse\_float=None*, *parse\_int=None*, *parse\_constant=None*, *object\_pairs\_hook=None*, *\*\*kw*)[¶](#jsonrpc.exceptions.JSONRPCError.deserialize "Permalink to this definition")

Deserialize `s` (a `str` or `unicode` instance containing a JSON

document) to a Python object.

If `s` is a `str` instance and is encoded with an ASCII based encoding

other than utf-8 (e.g. latin-1) then an appropriate `encoding` name

must be specified. Encodings that are not ASCII based (such as UCS-2)

are not allowed and should be decoded to `unicode` first.

`object\_hook` is an optional function that will be called with the

result of any object literal decode (a `dict`). The return value of

`object\_hook` will be used instead of the `dict`. This feature

can be used to implement custom decoders (e.g. JSON-RPC class hinting).

`object\_pairs\_hook` is an optional function that will be called with the

result of any object literal decoded with an ordered list of pairs. The

return value of `object\_pairs\_hook` will be used instead of the `dict`.

This feature can be used to implement custom decoders that rely on the

order that the key and value pairs are decoded (for example,

collections.OrderedDict will remember the order of insertion). If

`object\_hook` is also defined, the `object\_pairs\_hook` takes priority.

`parse\_float`, if specified, will be called with the string

of every JSON float to be decoded. By default this is equivalent to

float(num\_str). This can be used to use another datatype or parser

for JSON floats (e.g. decimal.Decimal).

`parse\_int`, if specified, will be called with the string

of every JSON int to be decoded. By default this is equivalent to

int(num\_str). This can be used to use another datatype or parser

for JSON integers (e.g. float).

`parse\_constant`, if specified, will be called with one of the

following strings: -Infinity, Infinity, NaN, null, true, false.

This can be used to raise an exception if invalid JSON numbers

are encountered.

To use a custom `JSONDecoder` subclass, specify it with the `cls`

kwarg; otherwise `JSONDecoder` is used.

*classmethod* `from_json`(*json\_str*)[[source]](_modules/jsonrpc/exceptions.html#JSONRPCError.from_json)[¶](#jsonrpc.exceptions.JSONRPCError.from_json "Permalink to this definition")

`json`[¶](#jsonrpc.exceptions.JSONRPCError.json "Permalink to this definition")

`message`[¶](#jsonrpc.exceptions.JSONRPCError.message "Permalink to this definition")

*static* `serialize`(*obj*, *skipkeys=False*, *ensure\_ascii=True*, *check\_circular=True*, *allow\_nan=True*, *cls=None*, *indent=None*, *separators=None*, *encoding='utf-8'*, *default=None*, *sort\_keys=False*, *\*\*kw*)[¶](#jsonrpc.exceptions.JSONRPCError.serialize "Permalink to this definition")

Serialize `obj` to a JSON formatted `str`.

If `skipkeys` is true then `dict` keys that are not basic types

(`str`, `unicode`, `int`, `long`, `float`, `bool`, `None`)

will be skipped instead of raising a `TypeError`.

If `ensure\_ascii` is false, all non-ASCII characters are not escaped, and

the return value may be a `unicode` instance. See `dump` for details.

If `check\_circular` is false, then the circular reference check

for container types will be skipped and a circular reference will

result in an `OverflowError` (or worse).

If `allow\_nan` is false, then it will be a `ValueError` to

serialize out of range `float` values (`nan`, `inf`, `-inf`) in

strict compliance of the JSON specification, instead of using the

JavaScript equivalents (`NaN`, `Infinity`, `-Infinity`).

If `indent` is a non-negative integer, then JSON array elements and

object members will be pretty-printed with that indent level. An indent

level of 0 will only insert newlines. `None` is the most compact

representation. Since the default item separator is `', '`, the

output might include trailing whitespace when `indent` is specified.

You can use `separators=(',', ': ')` to avoid this.

If `separators` is an `(item\_separator, dict\_separator)` tuple

then it will be used instead of the default `(', ', ': ')` separators.

`(',', ':')` is the most compact JSON representation.

`encoding` is the character encoding for str instances, default is UTF-8.

`default(obj)` is a function that should return a serializable version

of obj or raise TypeError. The default simply raises TypeError.

If *sort\_keys* is `True` (default: `False`), then the output of

dictionaries will be sorted by key.

To use a custom `JSONEncoder` subclass (e.g. one that overrides the

`.default()` method to serialize additional types), specify it with

the `cls` kwarg; otherwise `JSONEncoder` is used.

*exception* `jsonrpc.exceptions.``JSONRPCException`[[source]](_modules/jsonrpc/exceptions.html#JSONRPCException)[¶](#jsonrpc.exceptions.JSONRPCException "Permalink to this definition")

Bases: `exceptions.Exception`

JSON-RPC Exception.

*class* `jsonrpc.exceptions.``JSONRPCInternalError`(*code=None*, *message=None*, *data=None*)[[source]](_modules/jsonrpc/exceptions.html#JSONRPCInternalError)[¶](#jsonrpc.exceptions.JSONRPCInternalError "Permalink to this definition")

Bases: [`jsonrpc.exceptions.JSONRPCError`](#jsonrpc.exceptions.JSONRPCError "jsonrpc.exceptions.JSONRPCError")

Internal error.

Internal JSON-RPC error.

`CODE` *= -32603*[¶](#jsonrpc.exceptions.JSONRPCInternalError.CODE "Permalink to this definition")

`MESSAGE` *= 'Internal error'*[¶](#jsonrpc.exceptions.JSONRPCInternalError.MESSAGE "Permalink to this definition")

*class* `jsonrpc.exceptions.``JSONRPCInvalidParams`(*code=None*, *message=None*, *data=None*)[[source]](_modules/jsonrpc/exceptions.html#JSONRPCInvalidParams)[¶](#jsonrpc.exceptions.JSONRPCInvalidParams "Permalink to this definition")

Bases: [`jsonrpc.exceptions.JSONRPCError`](#jsonrpc.exceptions.JSONRPCError "jsonrpc.exceptions.JSONRPCError")

Invalid params.

Invalid method parameter(s).

`CODE` *= -32602*[¶](#jsonrpc.exceptions.JSONRPCInvalidParams.CODE "Permalink to this definition")

`MESSAGE` *= 'Invalid params'*[¶](#jsonrpc.exceptions.JSONRPCInvalidParams.MESSAGE "Permalink to this definition")

*class* `jsonrpc.exceptions.``JSONRPCInvalidRequest`(*code=None*, *message=None*, *data=None*)[[source]](_modules/jsonrpc/exceptions.html#JSONRPCInvalidRequest)[¶](#jsonrpc.exceptions.JSONRPCInvalidRequest "Permalink to this definition")

Bases: [`jsonrpc.exceptions.JSONRPCError`](#jsonrpc.exceptions.JSONRPCError "jsonrpc.exceptions.JSONRPCError")

Invalid Request.

The JSON sent is not a valid Request object.

`CODE` *= -32600*[¶](#jsonrpc.exceptions.JSONRPCInvalidRequest.CODE "Permalink to this definition")

`MESSAGE` *= 'Invalid Request'*[¶](#jsonrpc.exceptions.JSONRPCInvalidRequest.MESSAGE "Permalink to this definition")

*exception* `jsonrpc.exceptions.``JSONRPCInvalidRequestException`[[source]](_modules/jsonrpc/exceptions.html#JSONRPCInvalidRequestException)[¶](#jsonrpc.exceptions.JSONRPCInvalidRequestException "Permalink to this definition")

Bases: [`jsonrpc.exceptions.JSONRPCException`](#jsonrpc.exceptions.JSONRPCException "jsonrpc.exceptions.JSONRPCException")

Request is not valid.

*class* `jsonrpc.exceptions.``JSONRPCMethodNotFound`(*code=None*, *message=None*, *data=None*)[[source]](_modules/jsonrpc/exceptions.html#JSONRPCMethodNotFound)[¶](#jsonrpc.exceptions.JSONRPCMethodNotFound "Permalink to this definition")

Bases: [`jsonrpc.exceptions.JSONRPCError`](#jsonrpc.exceptions.JSONRPCError "jsonrpc.exceptions.JSONRPCError")

Method not found.

The method does not exist / is not available.

`CODE` *= -32601*[¶](#jsonrpc.exceptions.JSONRPCMethodNotFound.CODE "Permalink to this definition")

`MESSAGE` *= 'Method not found'*[¶](#jsonrpc.exceptions.JSONRPCMethodNotFound.MESSAGE "Permalink to this definition")

*class* `jsonrpc.exceptions.``JSONRPCParseError`(*code=None*, *message=None*, *data=None*)[[source]](_modules/jsonrpc/exceptions.html#JSONRPCParseError)[¶](#jsonrpc.exceptions.JSONRPCParseError "Permalink to this definition")

Bases: [`jsonrpc.exceptions.JSONRPCError`](#jsonrpc.exceptions.JSONRPCError "jsonrpc.exceptions.JSONRPCError")

Parse Error.

Invalid JSON was received by the server.

An error occurred on the server while parsing the JSON text.

`CODE` *= -32700*[¶](#jsonrpc.exceptions.JSONRPCParseError.CODE "Permalink to this definition")

`MESSAGE` *= 'Parse error'*[¶](#jsonrpc.exceptions.JSONRPCParseError.MESSAGE "Permalink to this definition")

*class* `jsonrpc.exceptions.``JSONRPCServerError`(*code=None*, *message=None*, *data=None*)[[source]](_modules/jsonrpc/exceptions.html#JSONRPCServerError)[¶](#jsonrpc.exceptions.JSONRPCServerError "Permalink to this definition")

Bases: [`jsonrpc.exceptions.JSONRPCError`](#jsonrpc.exceptions.JSONRPCError "jsonrpc.exceptions.JSONRPCError")

Server error.

Reserved for implementation-defined server-errors.

`CODE` *= -32000*[¶](#jsonrpc.exceptions.JSONRPCServerError.CODE "Permalink to this definition")

`MESSAGE` *= 'Server error'*[¶](#jsonrpc.exceptions.JSONRPCServerError.MESSAGE "Permalink to this definition")

#### Manager[¶](#module-jsonrpc.manager "Permalink to this headline")

*class* `jsonrpc.manager.``JSONRPCResponseManager`[[source]](_modules/jsonrpc/manager.html#JSONRPCResponseManager)[¶](#jsonrpc.manager.JSONRPCResponseManager "Permalink to this definition")

Bases: `object`

JSON-RPC response manager.

Method brings syntactic sugar into library. Given dispatcher it handles

request (both single and batch) and handles errors.

Request could be handled in parallel, it is server responsibility.

| Parameters: | * **request\_str** (*str*) – json string. Will be converted into

JSONRPC20Request, JSONRPC20BatchRequest or JSONRPC10Request

* **dispather** (*dict*) – dict<function\_name:function>.

 |

`RESPONSE_CLASS_MAP` *= {'1.0': <class 'jsonrpc.jsonrpc1.JSONRPC10Response'>, '2.0': <class 'jsonrpc.jsonrpc2.JSONRPC20Response'>}*[¶](#jsonrpc.manager.JSONRPCResponseManager.RESPONSE_CLASS_MAP "Permalink to this definition")

*classmethod* `handle`(*request\_str*, *dispatcher*)[[source]](_modules/jsonrpc/manager.html#JSONRPCResponseManager.handle)[¶](#jsonrpc.manager.JSONRPCResponseManager.handle "Permalink to this definition")

*classmethod* `handle_request`(*request*, *dispatcher*)[[source]](_modules/jsonrpc/manager.html#JSONRPCResponseManager.handle_request)[¶](#jsonrpc.manager.JSONRPCResponseManager.handle_request "Permalink to this definition")

Handle request data.

At this moment request has correct jsonrpc format.

| Parameters: | * **request** (*dict*) – data parsed from request\_str.

* **dispatcher** ([*jsonrpc.dispatcher.Dispatcher*](index.html#jsonrpc.dispatcher.Dispatcher "jsonrpc.dispatcher.Dispatcher")) –

 |

#### jsonrpc.backend.django module[¶](#jsonrpc-backend-django-module "Permalink to this headline")

