kaiju-app


Namekaiju-app JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://github.com/violet-black/kaiju-app
SummaryPython modular application and services
upload_time2024-05-05 17:16:30
maintainerNone
docs_urlNone
authorvioletblackdev@gmail.com
requires_python>=3.11
licenseMIT
keywords application microservice asyncio infrastructure
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![pypi](https://img.shields.io/pypi/v/kaiju-app.svg)](https://pypi.python.org/pypi/kaiju-app/)
[![docs](https://readthedocs.org/projects/kaiju-app/badge/?version=latest&style=flat)](https://kaiju-app.readthedocs.io)
[![codecov](https://codecov.io/gh/violet-black/kaiju-app/graph/badge.svg?token=FEUUMQELFX)](https://codecov.io/gh/violet-black/kaiju-app)
[![tests](https://github.com/violet-black/kaiju-app/actions/workflows/tests.yaml/badge.svg)](https://github.com/violet-black/kaiju-app/actions/workflows/tests.yaml)
[![mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

[![python](https://img.shields.io/pypi/pyversions/kaiju-app.svg)](https://pypi.python.org/pypi/kaiju-app/)

**kaiju-app** - application and service base classes. They can be used as
building blocks for various asyncio server applications. The library provides base classes, configuration loader and
application builder and service dependency resolution mechanisms.

# Installation

With pip and python 3.12+:

```bash
pip3 install kaiju-app
```

# How to use

See the [user guide](https://kaiju-app.readthedocs.io/guide.html) for more info.

Create a service with custom methods, initialization and de-initialization.

```python
from kaiju_app import Service

class CacheService(Service):

    def __init__(self, host: str, port: int, password: str):
        ...

    async def init(self):
        self._transport = await self._initialize_transport()

    async def close(self):
        self._transport.close()

    async def load_cache(self):
        ...

```

Create a loader and register your service class there.

```python
from kaiju_app import ApplicationLoader

loader = ApplicationLoader()
loader.service_classes['CacheService'] = CacheService
```

Load your configuration using a configurator and create an application with your services in it. You may use JSON
or YAML file loader here instead of implementing the whole config in Python.

```python
from kaiju_app import Configurator, ProjectConfig, AppConfig, ServiceConfig

example_config = ProjectConfig(
    packages=[],
    logging={},
    app=AppConfig(
        name='my_app',
        env='dev',
        services=[
            ServiceConfig(
                cls='CacheService',
                settings={
                    'host': '[cache_host]',
                    'port': '[cache_port]',
                    'password': '[cache_password]'
                }
            )
        ]
    )
)

example_env = {
    'cache_host': 'localhost',
    'cache_port': 6379,
    'cache_password': 'qwerty'
}

configurator = Configurator()
config = configurator.create_configuration([example_config], [example_env])
```

The idea behind configuration is that it split on two types of files: config (template) files and env files. Config
files are structured and must obey `ProjectConfig` special config format. Env files are flat and used to copy values
from, so env file may be a simple plain JSON or a text file or a set of environment variables. You can use any number
of template files and env files in your config - they will be merged.

The configurator uses [template-dict](http://template-dict.readthedocs.io) to fill the templates.

Next you can pass the resulting config to the `AppLoader` and create an application which can be run in an asyncio loop.
The `run_app` function allows you to run the app forever in an asyncio loop until a `ctrl+C` signal is received.

```python
from kaiju_app import run_app

app = loader.create_all(config)
run_app(app)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/violet-black/kaiju-app",
    "name": "kaiju-app",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "application, microservice, asyncio, infrastructure",
    "author": "violetblackdev@gmail.com",
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "[![pypi](https://img.shields.io/pypi/v/kaiju-app.svg)](https://pypi.python.org/pypi/kaiju-app/)\n[![docs](https://readthedocs.org/projects/kaiju-app/badge/?version=latest&style=flat)](https://kaiju-app.readthedocs.io)\n[![codecov](https://codecov.io/gh/violet-black/kaiju-app/graph/badge.svg?token=FEUUMQELFX)](https://codecov.io/gh/violet-black/kaiju-app)\n[![tests](https://github.com/violet-black/kaiju-app/actions/workflows/tests.yaml/badge.svg)](https://github.com/violet-black/kaiju-app/actions/workflows/tests.yaml)\n[![mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)\n[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n[![python](https://img.shields.io/pypi/pyversions/kaiju-app.svg)](https://pypi.python.org/pypi/kaiju-app/)\n\n**kaiju-app** - application and service base classes. They can be used as\nbuilding blocks for various asyncio server applications. The library provides base classes, configuration loader and\napplication builder and service dependency resolution mechanisms.\n\n# Installation\n\nWith pip and python 3.12+:\n\n```bash\npip3 install kaiju-app\n```\n\n# How to use\n\nSee the [user guide](https://kaiju-app.readthedocs.io/guide.html) for more info.\n\nCreate a service with custom methods, initialization and de-initialization.\n\n```python\nfrom kaiju_app import Service\n\nclass CacheService(Service):\n\n    def __init__(self, host: str, port: int, password: str):\n        ...\n\n    async def init(self):\n        self._transport = await self._initialize_transport()\n\n    async def close(self):\n        self._transport.close()\n\n    async def load_cache(self):\n        ...\n\n```\n\nCreate a loader and register your service class there.\n\n```python\nfrom kaiju_app import ApplicationLoader\n\nloader = ApplicationLoader()\nloader.service_classes['CacheService'] = CacheService\n```\n\nLoad your configuration using a configurator and create an application with your services in it. You may use JSON\nor YAML file loader here instead of implementing the whole config in Python.\n\n```python\nfrom kaiju_app import Configurator, ProjectConfig, AppConfig, ServiceConfig\n\nexample_config = ProjectConfig(\n    packages=[],\n    logging={},\n    app=AppConfig(\n        name='my_app',\n        env='dev',\n        services=[\n            ServiceConfig(\n                cls='CacheService',\n                settings={\n                    'host': '[cache_host]',\n                    'port': '[cache_port]',\n                    'password': '[cache_password]'\n                }\n            )\n        ]\n    )\n)\n\nexample_env = {\n    'cache_host': 'localhost',\n    'cache_port': 6379,\n    'cache_password': 'qwerty'\n}\n\nconfigurator = Configurator()\nconfig = configurator.create_configuration([example_config], [example_env])\n```\n\nThe idea behind configuration is that it split on two types of files: config (template) files and env files. Config\nfiles are structured and must obey `ProjectConfig` special config format. Env files are flat and used to copy values\nfrom, so env file may be a simple plain JSON or a text file or a set of environment variables. You can use any number\nof template files and env files in your config - they will be merged.\n\nThe configurator uses [template-dict](http://template-dict.readthedocs.io) to fill the templates.\n\nNext you can pass the resulting config to the `AppLoader` and create an application which can be run in an asyncio loop.\nThe `run_app` function allows you to run the app forever in an asyncio loop until a `ctrl+C` signal is received.\n\n```python\nfrom kaiju_app import run_app\n\napp = loader.create_all(config)\nrun_app(app)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python modular application and services",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://github.com/violet-black/kaiju-app"
    },
    "split_keywords": [
        "application",
        " microservice",
        " asyncio",
        " infrastructure"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "92d736d2dda3b5a289f815d014936c2a5b11ec12e6b794e9551d1ed8fce0fb1d",
                "md5": "e7dbdf3a5e89bec402370118aedbe676",
                "sha256": "6218bf26117ddfa7500c32213d2073653ab1a88bc6358826a40dd1418abe9de4"
            },
            "downloads": -1,
            "filename": "kaiju_app-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e7dbdf3a5e89bec402370118aedbe676",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 18659,
            "upload_time": "2024-05-05T17:16:30",
            "upload_time_iso_8601": "2024-05-05T17:16:30.212876Z",
            "url": "https://files.pythonhosted.org/packages/92/d7/36d2dda3b5a289f815d014936c2a5b11ec12e6b794e9551d1ed8fce0fb1d/kaiju_app-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-05 17:16:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "violet-black",
    "github_project": "kaiju-app",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "kaiju-app"
}
        
Elapsed time: 0.26337s