kaiju-app


Namekaiju-app JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/violet-black/kaiju-app
SummaryPython modular application and services
upload_time2024-05-02 15:12:38
maintainerNone
docs_urlNone
authorvioletblackdev@gmail.com
requires_python>=3.12
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.12",
    "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.4",
    "project_urls": {
        "Homepage": "https://github.com/violet-black/kaiju-app"
    },
    "split_keywords": [
        "application",
        " microservice",
        " asyncio",
        " infrastructure"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "56539a27f63e4a0621e8caf5e79181e802a4ccbce74fcb8bf7958432932e291d",
                "md5": "4f610678badf3d5bf5d4427e504929cf",
                "sha256": "463a947088945b0dba1e9f804c73bfd45895cf27c73bd59aa04fa4013073b296"
            },
            "downloads": -1,
            "filename": "kaiju_app-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4f610678badf3d5bf5d4427e504929cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 18876,
            "upload_time": "2024-05-02T15:12:38",
            "upload_time_iso_8601": "2024-05-02T15:12:38.202711Z",
            "url": "https://files.pythonhosted.org/packages/56/53/9a27f63e4a0621e8caf5e79181e802a4ccbce74fcb8bf7958432932e291d/kaiju_app-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-02 15:12:38",
    "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.26186s