A microservices framework for Python that lets service developers concentrate on application logic and encourages testability.

Microservices

“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

Example I

                        
    class HelloWorld(object):
        name = “hello”

        @rpc
        def greet(self, friend):
            return “Hello {}!”.format(friend)
                        
                    

Demo!

Nameko Concepts

  • Entrypoints
    • To interact with a service
  • Dependencies
    • For the service to interact with external things

Example II

                        
    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

Test Helpers

                                
        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!"
                                 
                            

Extensible

"Built-in" Extensions

  • AMQP RPC
  • AMQP Pub-Sub
  • HTTP based on Werkzeug
  • Timer
  • Websockets

"Community" Extensions

  • nameko-sentry
  • nameko-sqlalchemy
  • nameko-redis
  • nameko-slack
  • ... and more!
  • Made for microservices
  • Enables you to write clean, highly testable code
  • Designed to be extended
  • Useful out of the box

Thank you

Slides: https://mattbennett.github.io/nameko-london-python-presentation

Demo Files: https://github.com/mattbennett/nameko-london-python-demo