Skip to content

Commit 40a33ce

Browse files
authored
Create a basic documentation (#705)
1 parent c3fb11b commit 40a33ce

40 files changed

+1898
-343
lines changed

.readthedocs.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
version: 2
22
build:
3-
os: ubuntu-22.04
3+
os: ubuntu-24.04
44
tools:
5-
python: 'latest'
6-
python:
7-
install:
8-
- requirements: requirements/docs.txt
9-
- method: pip
10-
path: .
11-
sphinx:
12-
builder: dirhtml
13-
fail_on_warning: true
5+
python: '3.13'
6+
commands:
7+
- asdf plugin add uv
8+
- asdf install uv latest
9+
- asdf global uv latest
10+
- uv run --group docs sphinx-build -W -b dirhtml docs $READTHEDOCS_OUTPUT/html

bin/cibw-before-build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2024-2024, Cenobit Technologies, Inc. http://cenobit.es/
2+
# Copyright (c) 2024-2025, Cenobit Technologies, Inc. http://cenobit.es/
33
# All rights reserved.
44
#
55
# Redistribution and use in source and binary forms, with or without
1.12 MB
Loading
1.47 MB
Loading

docs/conf.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2012-2024, Cenobit Technologies, Inc. http://cenobit.es/
1+
# Copyright (c) 2012-2025, Cenobit Technologies, Inc. http://cenobit.es/
22
# All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without
@@ -27,18 +27,21 @@
2727
from pallets_sphinx_themes import ProjectLink, get_version
2828

2929
project = 'Flask-JSONRPC'
30-
copyright = '2021-2024, Nycholas de Oliveira e Oliveira'
30+
copyright = '2021-2025, Cenobit Technologies, Inc. http://cenobit.es/'
3131
author = 'Nycholas de Oliveira e Oliveira'
3232
release, version = get_version('Flask-JSONRPC')
3333

34-
master_doc = 'index'
3534
default_role = 'code'
3635
extensions = [
3736
'sphinx.ext.autodoc',
3837
'sphinx.ext.extlinks',
3938
'sphinx.ext.intersphinx',
39+
'sphinx.ext.autosummary',
40+
'sphinx.ext.viewcode',
41+
'sphinx.ext.napoleon',
4042
'sphinxcontrib.log_cabinet',
4143
'sphinx_tabs.tabs',
44+
# 'sphinx_autodoc_typehints',
4245
'pallets_sphinx_themes',
4346
]
4447
autodoc_member_order = 'bysource'
@@ -50,6 +53,7 @@
5053
extlinks = {
5154
'issue': ('https://github.com/cenobites/flask-jsonrpc/issues/%s', '#%s'),
5255
'pr': ('https://github.com/cenobites/flask-jsonrpc/pull/%s', '#%s'),
56+
'ghsa': ('https://github.com/cenobites/flask-jsonrpc/security/advisories/GHSA-%s', 'GHSA-%s'),
5357
}
5458
intersphinx_mapping = {
5559
'python': ('https://docs.python.org/3/', None),
@@ -73,9 +77,13 @@
7377
}
7478
singlehtml_sidebars = {'index': ['project.html', 'localtoc.html', 'ethicalads.html']}
7579
html_static_path = ['_static']
76-
# html_favicon = '_static/flask-jsonrpc-icon.png'
77-
# html_logo = '_static/flask-jsonrpc-icon.png'
80+
html_favicon = '_static/flask-jsonrpc-icon.svg'
81+
html_logo = '_static/flask-jsonrpc-icon.svg'
7882
html_title = f'Flask-JSONRPC Documentation ({version})'
7983
html_show_sourcelink = False
8084

81-
latex_documents = [(master_doc, f'Flask-JSONRPC-{version}.tex', html_title, author, 'manual')]
85+
gettext_uuid = True
86+
gettext_compact = False
87+
autosummary_generate = True
88+
napoleon_google_docstring = True
89+
add_module_names = False

docs/deployment.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Deployment
2+
==========
3+
4+
This section covers deploying Flask-JSONRPC services in production environments.
5+
6+
----
7+
8+
WSGI Servers
9+
------------
10+
11+
Use a WSGI server such as Gunicorn or uWSGI:
12+
13+
.. code-block:: bash
14+
15+
# Using Gunicorn
16+
gunicorn -w 4 -b 0.0.0.0:8000 app:create_app()
17+
18+
.. note::
19+
20+
Replace ``app:create_app()`` with your factory function if using app factories.
21+
22+
----
23+
24+
Reverse Proxy (Nginx Example)
25+
-----------------------------
26+
27+
Example configuration for Nginx forwarding to Gunicorn:
28+
29+
.. code-block:: nginx
30+
31+
server {
32+
listen 80;
33+
server_name example.com;
34+
35+
location /api {
36+
proxy_pass http://127.0.0.1:8000/api;
37+
proxy_set_header Host $host;
38+
proxy_set_header X-Real-IP $remote_addr;
39+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
40+
}
41+
}
42+
43+
----
44+
45+
HTTPS and Security
46+
------------------
47+
48+
* Always enable HTTPS in production.
49+
* Protect sensitive methods with authentication (see :doc:`patterns/auth`).
50+
* Disable the web explorer in public environments:
51+
52+
.. code-block:: python
53+
54+
JSONRPC(app, "/api", enable_web_browsable_api=False)
55+
56+
----
57+
58+
Scaling and Multiple Instances
59+
------------------------------
60+
61+
Use standard Flask/WSGI scaling:
62+
63+
* Multiple Gunicorn workers
64+
* Load balancer in front (NGINX, HAProxy)
65+
* Optional horizontal scaling across servers
66+
67+
Flask-JSONRPC methods remain stateless by default. Ensure shared state (like
68+
databases) is properly configured.

docs/index.rst

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,53 @@
1-
.. Flask-JSONRPC documentation master file, created by
2-
sphinx-quickstart on Wed Jul 14 14:54:46 2021.
3-
You can adapt this file completely to your liking, but it should at least
4-
contain the root `toctree` directive.
1+
.. rst-class:: hide-header
52

63
Welcome to Flask-JSONRPC's documentation!
74
=========================================
85

6+
.. image:: _static/flask-jsonrpc-name.png
7+
:align: center
8+
:height: 250px
9+
10+
Flask-JSONRPC brings full **JSON-RPC 2.0** support to your Flask applications.
11+
It is designed to feel natural to anyone who already knows Flask, and easy to
12+
learn for those who do not.
13+
14+
Flask-JSONRPC provides:
15+
16+
* a Pythonic decorator-based API for defining JSON-RPC methods
17+
* automatic request parsing and parameter handling
18+
* validation based on Python type hints
19+
* batch request support
20+
* method namespacing
21+
* an optional built-in web UI explorer for testing and debugging, `available here <https://flask-jsonrpc.cenobit.es/api/browse/#/>`__
22+
* an extension system that plays nicely with the Flask ecosystem
23+
24+
Flask-JSONRPC follows the JSON-RPC 2.0 specification and integrates naturally
25+
with Flask's routing, blueprints, and application factory patterns.
26+
27+
28+
User's Guide
29+
------------
30+
931
.. toctree::
1032
:maxdepth: 2
11-
:caption: Contents:
1233

34+
installation
35+
quickstart
36+
37+
tutorial/index
1338

39+
usage/methods
40+
usage/params
41+
usage/types
42+
usage/blueprints
43+
usage/batch
44+
usage/errors
45+
usage/explorer
1446

15-
Indices and tables
16-
==================
47+
patterns/factories
48+
patterns/auth
49+
patterns/validation
50+
patterns/marshaling
1751

18-
* :ref:`genindex`
19-
* :ref:`modindex`
20-
* :ref:`search`
52+
testing
53+
deployment

docs/installation.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Installation
2+
============
3+
4+
Flask-JSONRPC is available on PyPI and supports modern versions of Python and
5+
Flask.
6+
7+
Requirements
8+
------------
9+
10+
* Python 3.10 or later
11+
* Flask 3.x or later
12+
13+
Installation
14+
------------
15+
16+
Install using pip:
17+
18+
.. code-block:: bash
19+
20+
pip install Flask-JSONRPC
21+
22+
Verifying the Installation
23+
--------------------------
24+
25+
You can verify that Flask-JSONRPC is installed by running:
26+
27+
.. code-block:: bash
28+
29+
python -c "import flask_jsonrpc; print(flask_jsonrpc.__version__)"
30+
31+
Upgrading
32+
---------
33+
34+
To upgrade to the latest version:
35+
36+
.. code-block:: bash
37+
38+
pip install --upgrade Flask-JSONRPC

docs/patterns/auth.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Authentication Patterns
2+
=======================
3+
4+
Flask-JSONRPC does not include built-in authentication. Use Flask patterns to
5+
secure your endpoints.
6+
7+
----
8+
9+
Token-based Authentication
10+
--------------------------
11+
12+
You can require a token in request headers:
13+
14+
.. code-block:: python
15+
16+
from flask import request
17+
from flask_jsonrpc.exceptions import JSONRPCError
18+
19+
@jsonrpc.method("secret.echo")
20+
def echo(message: str):
21+
token = request.headers.get("X-Auth-Token")
22+
if token != "my-secret":
23+
raise JSONRPCError(code=401, message="Unauthorized")
24+
return message
25+
26+
----
27+
28+
JWT Authentication (Optional Extension)
29+
---------------------------------------
30+
31+
.. code-block:: python
32+
33+
import jwt
34+
35+
SECRET_KEY = "supersecret"
36+
37+
@jsonrpc.method("auth.verify")
38+
def verify(token: str):
39+
try:
40+
payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
41+
except jwt.InvalidTokenError:
42+
raise JSONRPCError(code=401, message="Invalid token")
43+
return payload

docs/patterns/factories.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Application Factories
2+
=====================
3+
4+
Flask recommends using **application factories** for flexibility and testability.
5+
Flask-JSONRPC integrates naturally with this pattern.
6+
7+
----
8+
9+
Creating an Application Factory
10+
-------------------------------
11+
12+
.. code-block:: python
13+
14+
from flask import Flask
15+
from flask_jsonrpc import JSONRPC
16+
17+
def create_app(config=None):
18+
app = Flask(__name__)
19+
if config:
20+
app.config.update(config)
21+
22+
# JSON-RPC endpoint
23+
jsonrpc = JSONRPC(app, "/api", enable_web_browsable_api=True)
24+
25+
# Example method
26+
@jsonrpc.method("ping")
27+
def ping():
28+
return "pong"
29+
30+
return app
31+
32+
----
33+
34+
Benefits
35+
--------
36+
37+
* Easy testing (create multiple app instances)
38+
* Clean separation between app and extensions
39+
* Works with blueprints and modular JSON-RPC endpoints

0 commit comments

Comments
 (0)