Insanic is a microservice framework that extends sanic. It tries to include all the best practices for developing in a microservice architecture. To do this, certain stacks were needed, as a result Insanic is a pretty opinionated framework.
Think of this as django-rest-framework is to django but for microservice usage (and a lot less functionality than drf).
We needed this because we need a framework for our developers to quickly develop services while migrating to a microservice architecture.
As stated before, this is very opinionated and the reason being, to reduce research time when trying to select packages to use for their service. It lays down all the necessary patterns and bootstraps the application for quick cycle time between idea and deployment.
- Authentication and Authorization for Users and other Services (like drf)
- Easy Service Requests
- Normalized Error Message Formats
- Connection manager to redis
- Utils for extracting public routes (will help when registering to api gateway)
- Bootstrap monitoring endpoints
- Throttling
For more detailed information please refer to the documentation
Core dependencies include:
- sanic - extends sanic
- httpx - to make async requests to other services
- PyJWT - for authentication
- Redis - for cache and throttling
To install:
$ pip install insanic-framework
For very basic usage, it is pretty much the same as Sanic:
- Create a python file. ex. app.py
from insanic import Insanic
from insanic.conf import settings
from sanic.response import json
settings.configure()
__version__ = "0.1.0"
app = Insanic(__name__, version=__version__)
@app.route('/')
async def example(request):
return json({"insanic": "Gotta go insanely fast!"})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
- Run with
python run.py
- Check in browser or curl
curl http://localhost:8000/
For more examples and usage, please refer to the documentation.
Insanic tests are run with pytest and tox.
$ pytest # with coverage $ pytest --cov=insanic --cov-report term-missing:skip-covered # a certain set of tests $ pytest --pytest-args tests/test_pact.py # tox, run for sanic > 19.12 and python >= 3.6 $ tox
For full changelogs, please refer to the CHANGELOG.rst.
Since Insanic was initially developed and released internally, for changes made during that period, please refer to CHANGELOG_LEGACY.rst.
For guidance on setting up a development environment and how to make a contribution to Insanic, see the CONTRIBUTING.rst guidelines.
- Insanic cannot run with more than 1 worker.
Distributed under the MIT license. See LICENSE for more information.
Thanks to all the people at my prior company that worked with me to make this possible.
- Documentation: http://insanic.readthedocs.io/
- Releases: https://pypi.org/project/insanic-framework/
- Code: https://www.github.com/crazytruth/insanic/
- Issue Tracker: https://www.github.com/crazytruth/insanic/issues
- Sanic Documentation: https://sanic.readthedocs.io/en/latest/index.html
- Sanic Repository: https://github.com/huge-success/sanic