# Orloj
[](https://pypi.org/project/orloj)
[](https://pypi.org/project/orloj)
[](https://pypi.org/project/orloj)
[](.)
[](.)
[](.)
[](.)
[](static/orloj-banner.svg)
## Getting started
You can use `orloj` simply by installing via `pip` on your Terminal.
```sh
pip install orloj
```
or alternatively when using [poetry](https://python-poetry.org) package manager as such:
```sh
poetry add orloj
```
And then you can begin using `OrlojMiddleware` in your ASGI project as such
```python
...
from orloj import OrlojMiddleware
def action() -> None:
  """Action to be called by scheduler"""
app.add_middleware(OrlojMiddleware, interval=3, job=action, job_id="scheduled-action")
...
```
The following example shows you how to setup `OrlojMiddleware` to run scheduled tasks alongside
your [FastAPI](https://github.com/tiangolo/fastapi) application.
```python
from fastapi import FastAPI
from logging import Logger, getLogger
from orloj import OrlojMiddleware
from starlette.responses import PlainTextResponse, RedirectResponse
app = FastAPI()
logger: Logger = getLogger("uvicorn")
def hello_name(name: str) -> None:
  logger.info(f"Hello, {name}!")
def hello_world() -> None:
  logger.info("Hello, World!")
@app.get("/")
async def redirect_to_swagger_docs() -> RedirectResponse:
  """Redirects to swagger documentation
  """
  return RedirectResponse("/docs")
@app.get("/health", response_class=PlainTextResponse, status_code=200)
async def health() -> str:
  """Health check
  """
  return "OK"
app.add_middleware(
  OrlojMiddleware, interval=3, job=hello_name, job_id="hello-igor", name="Igor"
)
app.add_middleware(
  OrlojMiddleware, interval=6, job=hello_world, job_id="hello-world"
)
```
## Dependencies
* [APScheduler](https://github.com/agronholm/apscheduler)
  [](https://pypi.org/project/APScheduler)
  [](https://apscheduler.readthedocs.io/en/3.x)
* [starlette](https://www.starlette.io)
  [](https://pypi.org/project/starlette)
  [](https://www.starlette.io)
## Contributions
To contribute to the project, fork the repository and clone to your local device and development
dependencies including three extra libraries not included in final builds as such:
* [mypy](https://github.com/python/mypy) - Optional static typing for Python
* [pytest](https://github.com/pytest-dev/pytest) - The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
* [ruff](https://github.com/astral-sh/ruff) - An extremely fast Python linter and code formatter, written in Rust. 
Use the following commands to setup your local environment with development dependencies:
```bash
pip install --user poetry
poetry install --with dev
```
## Acknowledgements
* [APScheduler Web Examples](https://github.com/agronholm/apscheduler/tree/master/examples/web)
* [Wikimedia Commons - File:Prague Astronomical Clock.svg](https://commons.wikimedia.org/wiki/File:Prague_Astronomical_Clock.svg)
## License
This project is licensed under the terms of the MIT license.
            
         
        Raw data
        
            {
    "_id": null,
    "home_page": null,
    "name": "orloj",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "asgi, blacksheep, fastapi, litestar, quart, sanic, starlette, uvicorn",
    "author": "Sitt Guruvanich",
    "author_email": "aekazitt+github@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/af/09/7aa45b012a983ea72d422c7a60b1353b33e75351d3f906e412a8045bbac0/orloj-0.1.4.tar.gz",
    "platform": null,
    "description": "# Orloj\n\n[](https://pypi.org/project/orloj)\n[](https://pypi.org/project/orloj)\n[](https://pypi.org/project/orloj)\n[](.)\n[](.)\n[](.)\n[](.)\n\n[](static/orloj-banner.svg)\n\n## Getting started\n\nYou can use `orloj` simply by installing via `pip` on your Terminal.\n\n```sh\npip install orloj\n```\n\nor alternatively when using [poetry](https://python-poetry.org) package manager as such:\n\n```sh\npoetry add orloj\n```\n\nAnd then you can begin using `OrlojMiddleware` in your ASGI project as such\n\n```python\n...\nfrom orloj import OrlojMiddleware\n\ndef action() -> None:\n  \"\"\"Action to be called by scheduler\"\"\"\n\napp.add_middleware(OrlojMiddleware, interval=3, job=action, job_id=\"scheduled-action\")\n...\n```\n\nThe following example shows you how to setup `OrlojMiddleware` to run scheduled tasks alongside\nyour [FastAPI](https://github.com/tiangolo/fastapi) application.\n\n```python\nfrom fastapi import FastAPI\nfrom logging import Logger, getLogger\nfrom orloj import OrlojMiddleware\nfrom starlette.responses import PlainTextResponse, RedirectResponse\n\napp = FastAPI()\nlogger: Logger = getLogger(\"uvicorn\")\n\ndef hello_name(name: str) -> None:\n  logger.info(f\"Hello, {name}!\")\n\ndef hello_world() -> None:\n  logger.info(\"Hello, World!\")\n\n@app.get(\"/\")\nasync def redirect_to_swagger_docs() -> RedirectResponse:\n  \"\"\"Redirects to swagger documentation\n  \"\"\"\n  return RedirectResponse(\"/docs\")\n\n@app.get(\"/health\", response_class=PlainTextResponse, status_code=200)\nasync def health() -> str:\n  \"\"\"Health check\n  \"\"\"\n  return \"OK\"\n\napp.add_middleware(\n  OrlojMiddleware, interval=3, job=hello_name, job_id=\"hello-igor\", name=\"Igor\"\n)\napp.add_middleware(\n  OrlojMiddleware, interval=6, job=hello_world, job_id=\"hello-world\"\n)\n```\n\n## Dependencies\n\n* [APScheduler](https://github.com/agronholm/apscheduler)\n  [](https://pypi.org/project/APScheduler)\n  [](https://apscheduler.readthedocs.io/en/3.x)\n\n* [starlette](https://www.starlette.io)\n  [](https://pypi.org/project/starlette)\n  [](https://www.starlette.io)\n\n## Contributions\n\nTo contribute to the project, fork the repository and clone to your local device and development\ndependencies including three extra libraries not included in final builds as such:\n\n* [mypy](https://github.com/python/mypy) - Optional static typing for Python\n* [pytest](https://github.com/pytest-dev/pytest) - The pytest framework makes it easy to write small tests, yet scales to support complex functional testing\n* [ruff](https://github.com/astral-sh/ruff) - An extremely fast Python linter and code formatter, written in Rust. \n\nUse the following commands to setup your local environment with development dependencies:\n\n```bash\npip install --user poetry\npoetry install --with dev\n```\n\n## Acknowledgements\n\n* [APScheduler Web Examples](https://github.com/agronholm/apscheduler/tree/master/examples/web)\n* [Wikimedia Commons - File:Prague Astronomical Clock.svg](https://commons.wikimedia.org/wiki/File:Prague_Astronomical_Clock.svg)\n\n## License\n\nThis project is licensed under the terms of the MIT license.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Scheduler middleware for ASGI frameworks",
    "version": "0.1.4",
    "project_urls": null,
    "split_keywords": [
        "asgi",
        " blacksheep",
        " fastapi",
        " litestar",
        " quart",
        " sanic",
        " starlette",
        " uvicorn"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4d56a5e0ebae2a3c90f3bd160eaa068e6ce448ac3a05bc22b840372937b5d1ab",
                "md5": "dc90f1c9d99adefed084110132753ca3",
                "sha256": "1d65f21de6e53dd79117e42a633745f6b6b943f8cfd9871247e6b12aee37d8ac"
            },
            "downloads": -1,
            "filename": "orloj-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dc90f1c9d99adefed084110132753ca3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 4826,
            "upload_time": "2024-08-07T14:27:30",
            "upload_time_iso_8601": "2024-08-07T14:27:30.061282Z",
            "url": "https://files.pythonhosted.org/packages/4d/56/a5e0ebae2a3c90f3bd160eaa068e6ce448ac3a05bc22b840372937b5d1ab/orloj-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "af097aa45b012a983ea72d422c7a60b1353b33e75351d3f906e412a8045bbac0",
                "md5": "2e20ffae470b4d863b6699acfc45ded0",
                "sha256": "56c466eb1c3f9dd4554c3c5af8edc1f4ae06be891bfdc0ad9c30c010548eb0a6"
            },
            "downloads": -1,
            "filename": "orloj-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "2e20ffae470b4d863b6699acfc45ded0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 4422,
            "upload_time": "2024-08-07T14:27:31",
            "upload_time_iso_8601": "2024-08-07T14:27:31.408227Z",
            "url": "https://files.pythonhosted.org/packages/af/09/7aa45b012a983ea72d422c7a60b1353b33e75351d3f906e412a8045bbac0/orloj-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-07 14:27:31",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "orloj"
}