This article lists solutions to create network servers in Python for different standard protocols: HTTP, FTP, SMTP, SOAP, syslog, WebDAV, ...
This page was created on the 2009-03-04 and last edited on the 2011-10-20.
Python standard library
First, the standard library provides client and server implementation for several network protocols out of the box: see http://docs.python.org/library/internet.html
HTTP server
The Python standard library provides a simple HTTP server implementation:
- BaseHTTPServer, to build your own server: see http://docs.python.org/library/basehttpserver.html
- SimpleHTTPServer, to serve local files and directories: http://docs.python.org/library/simplehttpserver.html
By the way, the quickest and easiest way to serve a local directory via HTTP is to launch SimpleHTTPServer with two lines in a shell or a CMD window (be careful though, this server is not secure at all and should only be used for local tests, as it may expose your whole hard drive!). For example if you use Python 2.6 on Windows:
C:\Users\user>cd C:\test |
If you need better performance and features or a more complete HTTP protocol support, I would suggest CherryPy:
- CherryPy is a lightweight web application framework with many features: http://www.cherrypy.org/
- The package also includes a very efficient HTTP server named CherryPyWSGIServer (in cherrypy.wsgiserver module) which may be used independently: http://www.cherrypy.org/wiki/WSGIServeMulipleApplications
HTTP proxy
It is sometimes useful to develop a HTTP proxy in Python to filter or modify HTTP requests and responses. This page provides a lot of information about various HTTP proxies developped in Python: http://proxies.xhaus.com/python/
See also my module CherryProxy, a filtering HTTP proxy extensible in Python.
FTP server
Python does not provide any FTP server in the standard library. You may try pyftpdlib: http://code.google.com/p/pyftpdlib/
SMTP server
In the standard library, see the smtpd module: http://docs.python.org/library/smtpd.html
smtpd may be used as a SMTP server or as a relay.
SOAP server
- SOAPpy and ZSI: http://pywebsvcs.sourceforge.net/
- SOAPy: http://soapy.sf.net/
- soaplib: http://trac.optio.webfactional.com/wiki/soaplib
XML-RPC server
See simplexmlrpcserver and docxmlrpcserver in the standard library:
- http://docs.python.org/library/simplexmlrpcserver.html
- http://docs.python.org/library/docxmlrpcserver.html
Syslog server
- rxlogd: http://rxlogd.sourceforge.net/
WebDAV
- wsgidav: http://code.google.com/p/wsgidav/
- PanDAV: http://ivoras.sharanet.org/projects/pandav.html
- pywebdav: http://code.google.com/p/pywebdav/
- PyDAV: http://users.sfo.com/~jdavis/Software/PyDAV/readme.html
- an interesting article about wsgidav and pywebdav (in French)