Metadata-Version: 2.1
Name: insanic-framework
Version: 0.9.2
Summary: An API framework that extends sanic with a focus on microservices.
Home-page: https://github.com/crazytruth/insanic
Author: Kwang Jin Kim
Author-email: kwangjinkim@gmail.com
License: MIT
Project-URL: Documentation, https://insanic.readthedocs.io/en/latest/
Project-URL: Source, https://github.com/crazytruth/insanic
Project-URL: Tracker, https://github.com/crazytruth/insanic/issues
Keywords: api framework sanic async asyncio microservice msa python python3
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Requires-Python: >=3.6
Requires-Dist: uvloop
Requires-Dist: sanic (<20.10,>=20.03)
Requires-Dist: aioredis (>=1.1.0)
Requires-Dist: PyJWT
Requires-Dist: aiotask-context
Requires-Dist: python-dateutil
Requires-Dist: prometheus-client (==0.5.0)
Requires-Dist: psutil
Requires-Dist: packaging

.. image:: https://github.com/crazytruth/insanic/raw/master/artwork/insanic200px.png
    :width: 200px
    :alt: Insanic


Insanic
=======

|Build Status| |Documentation Status| |Codecov|

|PyPI pyversions| |PyPI version| |PyPI license| |Black|

.. |Build Status| image:: https://github.com/crazytruth/insanic/workflows/Python%20Tests/badge.svg
    :target: https://github.com/crazytruth/insanic/actions?query=workflow%3A%22Python+Tests%22

.. |Documentation Status| image:: https://readthedocs.org/projects/insanic/badge/?version=latest
    :target: http://insanic.readthedocs.io/?badge=latest

.. |Codecov| image:: https://codecov.io/gh/crazytruth/insanic/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/crazytruth/insanic

.. |PyPI version| image:: https://img.shields.io/pypi/v/insanic-framework
    :target: https://pypi.org/project/insanic-framework/

.. |PyPI pyversions| image:: https://img.shields.io/pypi/pyversions/insanic-framework
    :target: https://pypi.org/project/insanic-framework/

.. |Black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

.. |PyPI license| image:: https://img.shields.io/github/license/crazytruth/insanic?style=flat-square
    :target: https://pypi.org/project/insanic-framework/

.. end-badges


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).

Why we needed this
------------------

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.

FEATURES
---------

- 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

Documentation
--------------

For more detailed information please refer to the `documentation`_

Installation
------------

Prerequisites
^^^^^^^^^^^^^

Core dependencies include:

- `sanic`_ - extends sanic
- `httpx`_ - to make async requests to other services
- `PyJWT`_ - for authentication
- `Redis`_ - for cache and throttling

To install:

.. code-block::

    $ pip install insanic-framework

.. _sanic: https://github.com/huge-success/sanic
.. _httpx: https://github.com/encode/httpx
.. _PyJWT: https://github.com/jpadilla/pyjwt/
.. _Redis: https://redis.io/


Usage
-----

For very basic usage, it is pretty much the same as Sanic:

1. Create a python file. ex. `app.py`

.. code-block:: python

    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)



2. Run with

.. code-block::

    python run.py


3. Check in browser or `curl`

.. code-block::

    curl http://localhost:8000/


For more examples and usage, please refer to the `documentation`_.

Testing
-------

Insanic tests are run with pytest and tox.

.. code-block::

    $ 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


Release History
---------------

For full changelogs, please refer to the `CHANGELOG.rst <CHANGELOG.rst>`_.

Since Insanic was initially developed and released internally,
for changes made during that period, please refer to
`CHANGELOG_LEGACY.rst <CHANGELOG_LEGACY.rst>`_.

Contributing
-------------

For guidance on setting up a development environment and
how to make a contribution to Insanic,
see the `CONTRIBUTING.rst <CONTRIBUTING.rst>`_ guidelines.


Known Issues
-------------

-   Insanic cannot run with more than 1 worker.


Meta
----

Distributed under the MIT license. See `LICENSE <LICENSE>`_ for more information.

Thanks to all the people at my prior company that worked with me to make this possible.

Links
-----

- 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

.. _documentation: http://insanic.readthedocs.io/


