comparison Sphinx/source/plugins/python.rst @ 343:fff45618262d

creating the documentation of the Python plugin
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 26 Mar 2020 18:42:31 +0100
parents
children f81b533a0fd0
comparison
equal deleted inserted replaced
342:ab1ec4009541 343:fff45618262d
1 .. _python-plugin:
2
3
4 Python plugin for Orthanc
5 =========================
6
7 .. contents::
8
9 Work-in-progress.
10
11
12
13 Samples
14 -------
15
16 Extending the REST API
17 ......................
18
19 .. highlight:: python
20
21 Here is a basic Python script that registers two new routes in the
22 REST API::
23
24 import orthanc
25 import pprint
26
27 def OnRest(output, uri, **request):
28 pprint.pprint(request)
29 print('Accessing uri: %s' % uri)
30 output.AnswerBuffer('ok\n', 'text/plain')
31
32 orthanc.RegisterRestCallback('/(to)(t)o', OnRest)
33 orthanc.RegisterRestCallback('/tata', OnRest)
34
35 .. highlight:: json
36
37 Here is the associated minimal configuration file for Orthanc
38 (provided the Python script is saved as ``rest.py``)::
39
40 {
41 "Plugins" : [ "." ],
42 "PythonScript" : "rest.py",
43 "PythonVerbose" : false
44 }
45
46 .. highlight:: bash
47
48 The route can then be accessed as::
49
50 $ curl http://localhost:8042/toto
51 ok
52