Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Simple web service to remotely call Python module functions and data so that they look a local object. No generators, minimal stubbing.
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Table of Contents


python-service is useful to call remote python code from a a client python script in a very simple way.

License is licensed under GNU Affero GPL version 3 or later. An special service 'affero' is provided to ease compliance.

The rest of the code is GNU Lesser GPL version 3 or later. In few words, you may freely use, modify and distribute this software as long as you redistribute it and any changes you did to the licenced software with the same conditions. Unlike the GNU GPL, the GNU Lesser GPL those conditions do not apply on the code that uses the licenced code.


  • Client: urllib2, urllib, urlparse, httplib, mimetypes
  • Server: webob, decorator
  • Tests: wsgi_intercept, unittest, urllib2, urllib, urlparse, httplib, mimetypes


No installation procedure is provided yet. Just copy the needed scripts side to your own files.

  • With your client:,
  • With your server:

How to setup the server

  • Setup a module (ie. with functions and variables
 version = "3.2"
 def myFunction(param) :
  	return "result: %s"%param

  • Create a Service object passing the module name as parameter.
 application = Service.Reload(Service.Service("MyModule"))

  • Pass the Service as the application object of a wgsi server.
    • With mod_wsgi (apache), just name it 'application'
    • You can use other dummy servers to test:
 from wsgiref.simple_server import make_server
 httpd = make_server(
 	'localhost', # Host name.
 	8051, # port
 	application, # application object

  • Check that it works by opening in a web server

How to setup the client

  • Create a subclass of ServiceStub representing the service
  • Implement methods like the ones in MyModule by calling
remoteCall, ie, for
 		def myFunction(self, param) :
 			return self.remoteCall( "myFunction", param=param)

  • Instantiate the stub in your client code and use it
 	service = MyModule("")


Default parameters

Any parameter can be set optional by setting a default in the server. You can accept any parameter by adding a **kwd parameter.

Accessing the request object

If you want to access the request, just add a first parameter named 'request' to your server function. It is a webob.Request object.

Sending files to the server

If you pass a file object to the stub, the file content will be passed as attached content and the server receives it as cgi.FieldStorage object.

Changing the content-type

By default, the content-type is 'text/plain', if you want to change it you can set a content_type property on the server function.

 def myFunction(param) :
 	return "result: %s"%param
 myFunction.content_type = 'text/html'

Forcing HTTP errors

Just raise any subclass of Service.HttpError in Service. Not all errors are defined, you can just subclass it yourself.


  • Add unit tests for the ServiceStub
  • Adding decorators
  • Addding easy to construct response objects
  • Signing client message
Something went wrong with that request. Please try again.