Changes between Initial Version and Version 1 of python-json-rpc-old

Show
Ignore:
Timestamp:
04/29/07 17:45:08 (3 years ago)
Author:
Jan-Klaas Kollhof (IP: 90.198.30.119)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • python-json-rpc-old

    v1 v1  
     1= JSON-RPC for python = 
     2 
     3A json-rpc package which implements JSON-RPC. 
     4 
     5You can [http://json-rpc.org/browser/tags/py-jsonrpc/ browse] the code or check it out  
     6using subversion from the [http://svn.json-rpc.org/tags/py-jsonrpc/ svn repository]. 
     7 
     8This implementation is currently in development. 
     9 
     10 
     11It provides functionality for making JSON-RPC services available through CGI. 
     12In addition it provides a mod_python handler for providing services through mod_python which is more perfomant than CGI. There is also some JSON-RPC over sockets implementation. 
     13 
     14== Installation == 
     15 
     16You will need [http://cheeseshop.python.org/pypi/simplejson simplejson] installed for the jsonrpc to run. 
     17 
     18Download jsonrpc and install it into python's {{{lib/site-packages/}}}. 
     19 
     20On Unix/Linux do the following as '''root''': 
     21{{{ 
     22$ easy_install simplejson 
     23$ svn co http://svn.json-rpc.org/trunk jsonrpc 
     24$ cd jsonrpc 
     25$ python setup.py install 
     26}}} 
     27 
     28== mod_python handler == 
     29 
     30The idea is that you only need to create a python module containing a service, put it in a directory and the rest is handled by the mod_python handler. 
     31 
     32For it to work you need to tell apache to add a python handler for a certain location or directory. 
     33It also works in .htaccess files: 
     34 
     35Example: 
     36 
     37{{{ 
     38<Directory /var/www/services > 
     39    AddHandler mod_python py 
     40    PythonHandler jsonrpc.apacheServiceHandler 
     41    PythonPath "sys.path+['path_to_jsonrpc_implementation']" 
     42</Directory> 
     43}}} 
     44 
     45You may have to set the {{{PythonPath}}} in the code above, so that mod_python can find the hanlder (see the [http://www.modpython.org/live/current/doc-html/dir-other-pp.html mod_python documentation]). 
     46 
     47Now, place a python file in the directory {{{/var/www/services/echo.py}}}. 
     48If that file is requested the {{{jsonrpc.apacheServiceHandler}}} will import the python module for that file and look for a service inside that module. 
     49 
     50You have 3 options to tell the handler what service you want to provide in your module. 
     51 
     52You either expose:  
     53 * a service object called '''{{{service}}}''' 
     54 * a function '''{{{getService()}}}''' which returns a service object 
     55 * a class '''{{{Service}}}''' which will be used to create a service object 
     56 
     57Example service script {{{/var/www/services/echo.py}}}: 
     58{{{ 
     59#!python 
     60 
     61class Service: 
     62    def echo(self, msg): 
     63        return msg 
     64 
     65service = Service() 
     66}}} 
     67 
     68 
     69All methods of the service object are now available through JSON-RPC over HTTP:[[br]] 
     70(service url:{{{http://yourdomain/services/echo.py}}}). 
     71 
     72 
     73== CGI handler == 
     74 
     75To be used to server services in a CGI environment. 
     76 
     77Example CGI script 
     78{{{ 
     79#!python 
     80#!/usr/bin/env python 
     81 
     82class Service: 
     83    def echo(self, msg): 
     84        return msg 
     85 
     86from jsonrpc.cgihandler import handleCGIRequest 
     87 
     88handleCGIRequest(Service()) 
     89}}} 
     90 
     91 
     92== TCP service server ==  
     93 
     94To be used to serve JSON-RPC over TCP. 
     95 
     96''This is under development'' 
     97 
     98{{{ 
     99#!python 
     100 
     101class Service: 
     102    def echo(self, msg): 
     103        return msg 
     104 
     105 
     106from jsonrpc.socketserver import ThreadedTCPServiceServer 
     107 
     108ThreadedTCPServiceServer(Service()).serve(('localhost', 5766)) 
     109}}} 
     110   
     111[[br]]