This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description
  • The service locator pattern is a very simple but useful pattern that helps you remove glue code from application code.
  • Decoupling the wiring of dependencies (glue code) can reduce your lines of code significantly and encourages loose coupling.
  • This allows you to depend on abstractions rather than on concretions, it makes adding additional functionality to your application much easier.
  • Configuration xml files are not pythonic and are often overcomplicated, class decorators are used instead.
  • Concrete service implementations should be placed in a services folder. All services subfolders will be discovered using discover_services function and all containing modules will be auto-loaded.
  • All services will be instantiated by the service locator as a singleton.


Please see test/integration/ for a sample project. Suppose you have an abstract service class that looks like this:
class MIMERecognizerService(object):
    def recognizes_extension(self, extension):

    def get_MIME_type(self):

Register a service like this:
from servicelocator.service_discoverer import discover_services

class PDFRecognizer(MIMERecognizerService):
    def recognizes_extension(self, extension):
        return extension == ".pdf"

    def get_MIME_type(self):
        return "application/pdf"

You can register as many services and service providers as you like. When you retrieve all MIMERecognizerServices using the lookup_all function, one of the results in the list will be a PDFRecognizer() instance.

In order for the service discovery process to find the PDFRecognizer, you need to place it in a services folder. Your directory structure might look something like this (’s removed for demo purposes):


You discover services like this:

from servicelocator.service_discoverer import discover_services


And that’s it. The discover_services will walk the project directory tree and import all python modules inside services folders.

To retrieve service providers for a service, use the lookup functions like this:

from servicelocator.lookup import global_lookup

MIMERecognizers = global_lookup.lookup_all(MIMERecognizerService)

This will get all concrete implementations of the MIMERecognizerService but the we do not need to know about the existence of any of these concrete implementations. Adding extra functionality is as simple as dropping a file inside a services directory, no additional code is necessary. This makes adding new service providers in a loosely coupled way very easy .

And if you know there is only one implementation of the service:

from servicelocator.lookup import global_lookup

MIMERecognizer = global_lookup.lookup(MIMERecognizerService)
Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
service-locator-0.1.3.tar.gz (2.7 kB) Copy SHA256 Checksum SHA256 Source Aug 11, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting