changeset 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 ab1ec4009541
children 9f82ecc5a422
files Sphinx/source/plugins/python.rst
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sphinx/source/plugins/python.rst	Thu Mar 26 18:42:31 2020 +0100
@@ -0,0 +1,52 @@
+.. _python-plugin:
+
+
+Python plugin for Orthanc
+=========================
+
+.. contents::
+
+Work-in-progress.
+
+
+
+Samples
+-------
+
+Extending the REST API
+......................
+
+.. highlight:: python
+
+Here is a basic Python script that registers two new routes in the
+REST API::
+
+  import orthanc
+  import pprint
+
+  def OnRest(output, uri, **request):
+      pprint.pprint(request)
+      print('Accessing uri: %s' % uri)
+      output.AnswerBuffer('ok\n', 'text/plain')
+    
+  orthanc.RegisterRestCallback('/(to)(t)o', OnRest)
+  orthanc.RegisterRestCallback('/tata', OnRest)
+
+.. highlight:: json
+
+Here is the associated minimal configuration file for Orthanc
+(provided the Python script is saved as ``rest.py``)::
+
+  {
+    "Plugins" : [ "." ],
+    "PythonScript" : "rest.py",
+    "PythonVerbose" : false
+  }
+
+.. highlight:: bash
+
+The route can then be accessed as::
+
+  $ curl http://localhost:8042/toto
+  ok
+