skip to navigation
skip to content

sparts 0.5.0

Build services in python with as little code as possible

Package Documentation

Latest Version: 0.7.3

There is a lot of boilerplate and copypasta associated with building services (or any other software that runs continuously and does things)

sparts is a python library developed at Facebook that aims to eliminate as much of the skeleton code as possible, making it as dead simple to write new services with little to no excess code.

Design Goals

  • Be able to implement services with as little code as possible
  • Support as many RPC transports as possible (thrift, http, dbus, etc)
  • Make it painless to integrate services that require custom IO loops (twisted, tornado, glib, etc)


A sparts service typically consists of two parts, the core “service”, and its “tasks”. Background and offline processing is generally done by tasks, while common or shared functionality belongs to the service.


sparts.vtask.VService - This is the core of any sparts service.

Simply subclass VService for any custom service instance logic, and run its initFromCLI() and you are done.

For example,

from sparts.vservice import VService
class MyService(VService):


Now, you can run this file with the -h option (to see the available options), or run with: python

This should emit something like the following output:

DEBUG:VService:All tasks started``

And pressing ^C will emit:

^CINFO:VService:KeyboardInterrupt Received!  Stopping Tasks...
INFO:VService:Instance shut down gracefully

This simple service, by itself, is pretty damn useless. That’s where Tasks come into play


sparts.vtask.VTask - This is the base class for all tasks

Tasks are what trigger your program to take action. This action can be processing periodic events, handling HTTP requests, handling thrift requests, working on items from a queue, waking up on an event, operating some ioloop, or whatever.

Here’s a simple example of a service with tasks (requires tornado installed):

from sparts.vservice import VService
from sparts.tasks.tornado import TornadoHTTPTask

Now running it emits:

> python --http-port 8000
INFO:VService.TornadoHTTPTask:TornadoHTTPTask Server Started on (port 8000)
INFO:VService.TornadoHTTPTask:TornadoHTTPTask Server Started on :: (port 8000)
DEBUG:MyService:All tasks started

And as you can see, you can curl the webserver:

> curl localhost:8000
Hello, world

Tasks can be subclassed to do all kinds of things. This one prints the current unix timestamp every second:

from sparts.tasks.periodic import PeriodicTask

class PrintClock(PeriodicTask):
    INTERVAL = 1.0
    def execute(self):
        print time.time()

from sparts.vservice import VService

And the result:

DEBUG:VService:All tasks started
DEBUG:VService:VService Active.  Awaiting graceful shutdown.


If you have any questions, comments, feedback, suggestions, etc, please feel free to contact me at any time.


sparts is BSD-licensed. We also provide an additional patent grant.

File Type Py Version Uploaded on Size
sparts-0.5.0-py2.6.egg (md5) Python Egg 2.6 2014-04-18 135KB
sparts-0.5.0-py2.7.egg (md5) Python Egg 2.7 2014-04-18 136KB
sparts-0.5.0-py3.3.egg (md5) Python Egg 3.3 2014-04-18 144KB
sparts-0.5.0.tar.gz (md5) Source 2014-04-18 34KB
  • Downloads (All Versions):
  • 3 downloads in the last day
  • 453 downloads in the last week
  • 2702 downloads in the last month