Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

A service locator for python.

Project description

luogo is a basic service locator for Python3. I’ve been working a lot with dependency injection and service location in Java and thought it would be interesting to build something from scratch in my current language of choice.

Why the name luogo? I’m not brimming with funny/clever ideas at the moment; however, I’ve been watching this Italian crime drama which has inspired me to work on my Italian…

You might have guessed by now that “luogo” is Italian for location or place.

Installation

pip install luogo

Usage

You can start by defining your services in a service file (must feature “service” in the name). Services are denoted with the Service decorator.

# world_servce.py
from luogo import Service


@Service
class HelloWorldService:

    def greeting(self):
        return "Hello World!"

Your service client or implementation can then be in any file or module.

# client.py
from luogo import Locator, Implementation


@Implementation
class HelloWorldServiceClient:

    def greeting(self):
        service = Locator.get_service("HelloWorldService")
        return service.greeting()
print(HelloWorldServiceClient().greeting())
# Hello World!

You can also mark functions as services:

# world_service.py
from luogo import Service


@Service
def hello_world_service:
    return "Hello World!"
# client.py
from luogo import Locator, Implementation


@Implementation
def hello_world_service_client:
    return Locator.get_service("hello_world_service")
print(hello_world_service_client())
# Hello World!

Notes

  • I finally made it a thing to start using python3 so this probably isn’t python2 compatible (might have used a python3 lib somewhere). I might work on it though.
  • Services need to be a file that features the word service somewhere in the file name; however, implementations can be anywhere.
  • Locator depends on a case insensitive string representation of the service name; however, it’s easy to get that if you don’t always feel like typing it out.

Works for my purposes, hopefully it can be of use to someone else!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
luogo-0.1.0.tar.gz (4.6 kB) Copy SHA256 hash SHA256 Source None May 5, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page