<commit_before>jsonrpcserver
=============

A Flask-based [JSON-RPC 2.0](http://www.jsonrpc.org/) server library.

Create a Flask app, and register the jsonrpcserver blueprint to it.

    import sys, flask, jsonrpcserver

    app = flask.Flask(__name__)
    app.register_blueprint(jsonrpcserver.bp)

The blueprint will ensure we respond with JSON-RPC every time. For example, on
404, we respond with the JSON-RPC error, *Invalid request*.

Now create a route to handle the RPC methods:

    @app.route('/', methods=['POST'])
    def index():
        return jsonrpcserver.dispatch(sys.modules[__name__])

The ``dispatch`` command will validate the RPC request, and call the requested
*method*. We pass the current module to it, as the handler of the methods.

Now write your RPC methods, as you would any other python function:

    def add(num1, num2):
        return num1 + num2

You can even receive positional or keyword arguments.

    def find(name, *args, **kwargs):
        pass

If there's a problem with the arguments, you should raise the ``InvalidParams``
exception:

    def add(num1, num2='Not a number'):
        try:
            return num1 + num2
        except:
            raise jsonrpcserver.exceptions.InvalidParams()

If you need a client library, try my
[jsonrpcclient](https://bitbucket.org/beau-barker/jsonrpcclient).<commit_msg>Adjusted readme<commit_after>jsonrpcserver
=============

A Flask-based [JSON-RPC 2.0](http://www.jsonrpc.org/) server library.

Create a Flask app, and register the jsonrpcserver blueprint to it.

    import sys, flask, jsonrpcserver

    app = flask.Flask(__name__)
    app.register_blueprint(jsonrpcserver.bp)

The blueprint will ensure we respond with JSON-RPC every time. For example, on
404, we respond with the JSON-RPC error, *Invalid request*.

Now create a route to handle the RPC methods:

    @app.route('/', methods=['POST'])
    def index():
        return jsonrpcserver.dispatch(sys.modules[__name__])

The ``dispatch`` command will validate the RPC request, and call the requested
*method*. We pass the current module to it, as the handler of the methods.

Now write your RPC methods, as you would any other python function:

    def add(num1, num2):
        return num1 + num2

You can even receive positional or keyword arguments.

    def find(name, *args, **kwargs):
        pass

If there's a problem with the arguments, you should raise the ``InvalidParams``
exception:

    def add(num1, num2='Not a number'):
        try:
            return num1 + num2
        except TypeError:
            raise jsonrpcserver.exceptions.InvalidParams()

If you need a client library, try my
[jsonrpcclient](https://bitbucket.org/beau-barker/jsonrpcclient).
{'fraction_non_alphanumeric': 0.09860191317144959, 'fraction_numerical': 0.009565857247976454, 'mean_word_length': 3.5091210613598673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1709142', 'n_tokens_mistral': 794, 'n_tokens_neox': 763, 'n_words': 307}