Skip to main content

Python 3 microservice framework using asyncio with HTTP, AMQP and AWS SNS+SQS support.

Project description

tomodachi - a lightweight microservices framework with asyncio

https://travis-ci.org/kalaspuff/tomodachi.svg?branch=master https://img.shields.io/pypi/v/tomodachi.svg https://codecov.io/gh/kalaspuff/tomodachi/branch/master/graph/badge.svg https://img.shields.io/pypi/pyversions/tomodachi.svg

Python 3 microservice framework using asyncio (async / await) with HTTP, RabbitMQ / AMQP and AWS SNS+SQS support for event bus based communication.

Tomodachi is a tiny framework designed to build fast microservices listening on HTTP or communicating over event driven message buses like RabbitMQ, AMQP, AWS (Amazon Web Services) SNS+SQS, etc. It’s designed to be extendable to make use of any type of transport layer available.

Tomodachi (友達) means friends – and since microservices wouldn’t make sense on their own I think they need to be friends with each other. 😍 👬 👭 👫

How do I use this?

Installation via pip 🌮

$ pip install tomodachi

Basic HTTP based service 🌟

import tomodachi
from tomodachi.transport.http import http, http_error


@tomodachi.service
class HttpService(object):
    name = 'http_service'

    # Request paths are specified as regex for full flexibility
    @http('GET', r'/resource/(?P<id>[^/]+?)/?')
    async def resource(self, request, id):
        # Returning a string value normally means 200 OK
        return 'id = {}'.format(id)

    @http('GET', r'/health')
    async def health_check(self, request):
        # Return can also be a tuple, dict or even an aiohttp.web.Response
        # object for more complex responses - for example if you need to
        # send byte data, set your own status code or define own headers
        return {
            'body': 'Healthy',
            'status': 200
        }

    # Specify custom 404 catch-all response
    @http_error(status_code=404)
    async def error_404(self, request):
        return 'error 404'

Run service 😎

$ tomodachi run service.py

Requirements 👍

License 🙋

Offered under the MIT license

Source code 🦄

The latest developer version of tomodachi is available at the GitHub repo https://github.com/kalaspuff/tomodachi

Any questions?

What is the best way to run a tomodachi service?
There is no way to tell you how to orchestrate your infrastructure. Some people may run it containerized in a Docker environment, deployed via Terraform and some may run several services on the same environment, on the same machine. There are no standards and we’re not here to tell you about your best practices.
Are there any more example services?
There are a few examples in the examples folder, including examples to publish events/messages to an AWS SNS topic and subscribe to an AWS SQS queue. There’s also a similar example of how to work with pub-sub for RabbitMQ via AMQP transport protocol.
Why should I use this?
I’m not saying you should, but I’m not saying you shouldn’t. tomodachi is a perfect place to start when experimenting with your architecture or trying out a concept for a new service. It may not have all the features you desire and it may never do.
Should I run this in production?
It’s all still highly experimental and it depends on other experimental projects, so you have to be in charge here and decide for yourself. Let me know if you do however!
Who built this and why?
My name is Carl Oscar Aaro and I’m a coder from Sweden. I simply wanted to learn more about asyncio and needed a constructive off-work project to experiment with – and here we are. 🎉

Project details


Release history Release notifications | RSS feed

This version

0.2.0

Download files

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

Files for tomodachi, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size tomodachi-0.2.0-py3-none-any.whl (30.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size tomodachi-0.2.0.tar.gz (21.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page