A microservices framework for Python that lets service developers concentrate on application logic and encourages testability.
“The microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms“
class HelloWorld(object):
name = “hello”
@rpc
def greet(self, friend):
return “Hello {}!”.format(friend)
class HelloWorld(object):
name = “hello”
cache = CacheClient() # dependency declaration
@http("GET", "/hello/<string:friend>")
def greet(self, request, friend):
greeting = self.cache.get(friend)
if greeting is None:
greeting = “Hello {}!”.format(friend) # expensive
self.cache.put(friend, greeting)
return greeting
>>> HelloWorld.CacheClient
... <CacheClient [unbound] at 0x10cbb2750> # DependencyProvider
>>> self.cache
... <memcache.Client object at 0x10cbd25d0> # injected dependency
“... lets service developers concentrate on application logic and encourages testability“
from mock import call
from nameko.testing.services import worker_factory
hello_svc = worker_factory(HelloWorld)
hello_svc.cache.get.return_value = None
assert hello_svc.greet("Matt") == "Hello Matt!"
assert hello_svc.cache.get.call_args_list == [call("Matt")]
“... lets service developers concentrate on application logic and encourages testability“
import mockcache
from nameko.testing.services import worker_factory
fake_cache = mockcache.Client()
hello_svc = worker_factory(HelloWorld, cache=fake_cache)
assert hello_svc.greet("Matt") == "Hello Matt!"
assert fake_cache.get("Matt") == "Hello Matt!"
"Built-in" Extensions
"Community" Extensions