artless-framework


Nameartless-framework JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryArtless and minimalistic web framework without dependencies, working over WSGI.
upload_time2024-08-26 08:05:17
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords artless minimalistic web framework
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # artless-framework

<!-- ![Build Status](https://github.com/p3t3rbr0/py3-artless-framework/actions/workflows/ci.yaml/badge.svg?branch=master) -->
[![Downloads](https://static.pepy.tech/badge/artless-framework)](https://pepy.tech/project/artless-framework)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/artless-framework)
![PyPI Version](https://img.shields.io/pypi/v/artless-framework)
<!-- [![Code Coverage](https://codecov.io/gh/p3t3rbr0/py3-artless-framework/graph/badge.svg?token=N7J33ZOKVO)](https://codecov.io/gh/p3t3rbr0/py3-artless-framework) -->
<!-- [![Maintainability](https://api.codeclimate.com/v1/badges/76cc047808f3dc53de01/maintainability)](https://codeclimate.com/github/p3t3rbr0/py3-artless-framework/maintainability) -->

The artless and minimalistic web framework without dependencies, working over WSGI.

## Main principles

1. Artless, fast and small (less then 1000 LOC into single file) WSGI-framework.
2. No third party dependencies (standart library only).
3. Support only modern versions of Python (>=3.10).
4. Mostly pure functions without side effects.
5. Interfaces with type annotations.
6. Comprehensive documentation with examples of use.
7. Full test coverage.

## Limitations

* No built-in support for working with `Cookies`.
* Requests with `multipart/form-data` content-type are not supported.
* No built-in protections, such as: CSRF, XSS, clickjacking and other attack techniques.

## Installation

``` shellsession
$ pip install artless-framework
```

## Usages

``` python
from http import HTTPStatus
from os import getenv
from string import Template

from artless import App, Request, Response, ResponseFactory

HTML_TEMPLATE = Template(
    """
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <title>Say hello</title>
      </head>
      <body>
        <h1>Hello, $username!</h1>
      </body>
    </html>
    """
)


def say_hello(request: Request, username: str) -> Response:
    available_formats = {
        "json": ResponseFactory.json({"hello": username}),
        "plain": ResponseFactory.plain(f"Hello, {username}!"),
        "html": ResponseFactory.html(HTML_TEMPLATE.substitute(username=username)),
    }

    format = request.query.get("format", ["plain"])[0]

    if format not in available_formats:
        return ResponseFactory.create(status=HTTPStatus.BAD_REQUEST)

    return available_formats[format]


def create_application() -> App:
    app = App()
    app.set_routes([("GET", r"^/hello/(?P<username>\w+)$", say_hello)])
    return app


application = create_application()

if __name__ == "__main__":
    from wsgiref.simple_server import make_server

    host = getenv("HOST", "127.0.0.1")
    port = int(getenv("PORT", 8000))

    with make_server(host, port, application) as httpd:
        print(f"Started WSGI server on {host}:{port}")
        httpd.serve_forever()
```

Run it:

``` shellsession
$ python3 app.py
Started WSGI server on 127.0.0.1:8000
```

Check it:

``` shellsession
$ curl http://127.0.0.1:8000/hello/Peter
Hello, Peter!

$ curl http://127.0.0.1:8000/hello/Peter?format=html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Say hello</title>
  </head>
  <body>
    <h1>Hello, Peter!</h1>
  </body>
</html>

$ curl http://127.0.0.1:8000/hello/Peter?format=json
{"hello": "Peter"}
```

See more [examples](https://git.peterbro.su/peter/py3-artless-framework/src/branch/master/examples).

## Configureation

By default, the application defines the following config:

``` python
{
    "DEBUG": False,
    "TEMPLATES_DIR": "templates",
    "LOGGING": {
        "version": 1,
        "disable_existing_loggers": False,
        "formatters": {
            "default": {
                "format": "[{asctime}] [{process:d}] [{levelname}] {message}",
                "datefmt": "%Y-%m-%d %H:%M:%S",
                "style": "{",
            },
        },
        "handlers": {
            "stdout": {
                "formatter": "default",
                "level": "INFO",
                "class": "logging.StreamHandler",
                "stream": "ext://sys.stdout",
            }
        },
        "loggers": {
            "artless": {
                "level": "INFO",
                "handlers": ["stdout"],
                "propagate": False,
            }
        },
        "root": {"level": "WARNING", "handlers": ["stdout"]},
    },
}
```

Before creating an application instance, set the configuration by overriding existing values ​​and/or adding a new ones:

``` python
from artless import Config, App


Config().replace({"debug": True, "database": {"host": "localhost"}})
application = App()
```

To get values ​​from the config, anywhere in the application:

``` python
from artless import Config


db_host = Config().database.get("host")
...
```

## Roadmap

- [ ] Add ASGI support.
- [ ] Add plugin support.
- [ ] Add cookies support.
- [ ] Add async interface.
- [ ] Add `multipart/form-data` support.
- [ ] Add test client.
- [ ] Add benchmarks.
- [ ] Add more examples.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "artless-framework",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "artless, minimalistic, web, framework",
    "author": null,
    "author_email": "Peter Bro <p3t3rbr0@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/97/31/1ff7fc7f27d64856c41679770417a0f40b55f329d8f3c9ee5d5be66e3171/artless_framework-0.1.3.tar.gz",
    "platform": null,
    "description": "# artless-framework\n\n<!-- ![Build Status](https://github.com/p3t3rbr0/py3-artless-framework/actions/workflows/ci.yaml/badge.svg?branch=master) -->\n[![Downloads](https://static.pepy.tech/badge/artless-framework)](https://pepy.tech/project/artless-framework)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/artless-framework)\n![PyPI Version](https://img.shields.io/pypi/v/artless-framework)\n<!-- [![Code Coverage](https://codecov.io/gh/p3t3rbr0/py3-artless-framework/graph/badge.svg?token=N7J33ZOKVO)](https://codecov.io/gh/p3t3rbr0/py3-artless-framework) -->\n<!-- [![Maintainability](https://api.codeclimate.com/v1/badges/76cc047808f3dc53de01/maintainability)](https://codeclimate.com/github/p3t3rbr0/py3-artless-framework/maintainability) -->\n\nThe artless and minimalistic web framework without dependencies, working over WSGI.\n\n## Main principles\n\n1. Artless, fast and small (less then 1000 LOC into single file) WSGI-framework.\n2. No third party dependencies (standart library only).\n3. Support only modern versions of Python (>=3.10).\n4. Mostly pure functions without side effects.\n5. Interfaces with type annotations.\n6. Comprehensive documentation with examples of use.\n7. Full test coverage.\n\n## Limitations\n\n* No built-in support for working with `Cookies`.\n* Requests with `multipart/form-data` content-type are not supported.\n* No built-in protections, such as: CSRF, XSS, clickjacking and other attack techniques.\n\n## Installation\n\n``` shellsession\n$ pip install artless-framework\n```\n\n## Usages\n\n``` python\nfrom http import HTTPStatus\nfrom os import getenv\nfrom string import Template\n\nfrom artless import App, Request, Response, ResponseFactory\n\nHTML_TEMPLATE = Template(\n    \"\"\"\n    <!DOCTYPE html>\n    <html lang=\"en\">\n      <head>\n        <meta charset=\"utf-8\">\n        <title>Say hello</title>\n      </head>\n      <body>\n        <h1>Hello, $username!</h1>\n      </body>\n    </html>\n    \"\"\"\n)\n\n\ndef say_hello(request: Request, username: str) -> Response:\n    available_formats = {\n        \"json\": ResponseFactory.json({\"hello\": username}),\n        \"plain\": ResponseFactory.plain(f\"Hello, {username}!\"),\n        \"html\": ResponseFactory.html(HTML_TEMPLATE.substitute(username=username)),\n    }\n\n    format = request.query.get(\"format\", [\"plain\"])[0]\n\n    if format not in available_formats:\n        return ResponseFactory.create(status=HTTPStatus.BAD_REQUEST)\n\n    return available_formats[format]\n\n\ndef create_application() -> App:\n    app = App()\n    app.set_routes([(\"GET\", r\"^/hello/(?P<username>\\w+)$\", say_hello)])\n    return app\n\n\napplication = create_application()\n\nif __name__ == \"__main__\":\n    from wsgiref.simple_server import make_server\n\n    host = getenv(\"HOST\", \"127.0.0.1\")\n    port = int(getenv(\"PORT\", 8000))\n\n    with make_server(host, port, application) as httpd:\n        print(f\"Started WSGI server on {host}:{port}\")\n        httpd.serve_forever()\n```\n\nRun it:\n\n``` shellsession\n$ python3 app.py\nStarted WSGI server on 127.0.0.1:8000\n```\n\nCheck it:\n\n``` shellsession\n$ curl http://127.0.0.1:8000/hello/Peter\nHello, Peter!\n\n$ curl http://127.0.0.1:8000/hello/Peter?format=html\n\n<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\">\n    <title>Say hello</title>\n  </head>\n  <body>\n    <h1>Hello, Peter!</h1>\n  </body>\n</html>\n\n$ curl http://127.0.0.1:8000/hello/Peter?format=json\n{\"hello\": \"Peter\"}\n```\n\nSee more [examples](https://git.peterbro.su/peter/py3-artless-framework/src/branch/master/examples).\n\n## Configureation\n\nBy default, the application defines the following config:\n\n``` python\n{\n    \"DEBUG\": False,\n    \"TEMPLATES_DIR\": \"templates\",\n    \"LOGGING\": {\n        \"version\": 1,\n        \"disable_existing_loggers\": False,\n        \"formatters\": {\n            \"default\": {\n                \"format\": \"[{asctime}] [{process:d}] [{levelname}] {message}\",\n                \"datefmt\": \"%Y-%m-%d %H:%M:%S\",\n                \"style\": \"{\",\n            },\n        },\n        \"handlers\": {\n            \"stdout\": {\n                \"formatter\": \"default\",\n                \"level\": \"INFO\",\n                \"class\": \"logging.StreamHandler\",\n                \"stream\": \"ext://sys.stdout\",\n            }\n        },\n        \"loggers\": {\n            \"artless\": {\n                \"level\": \"INFO\",\n                \"handlers\": [\"stdout\"],\n                \"propagate\": False,\n            }\n        },\n        \"root\": {\"level\": \"WARNING\", \"handlers\": [\"stdout\"]},\n    },\n}\n```\n\nBefore creating an application instance, set the configuration by overriding existing values \u200b\u200band/or adding a new ones:\n\n``` python\nfrom artless import Config, App\n\n\nConfig().replace({\"debug\": True, \"database\": {\"host\": \"localhost\"}})\napplication = App()\n```\n\nTo get values \u200b\u200bfrom the config, anywhere in the application:\n\n``` python\nfrom artless import Config\n\n\ndb_host = Config().database.get(\"host\")\n...\n```\n\n## Roadmap\n\n- [ ] Add ASGI support.\n- [ ] Add plugin support.\n- [ ] Add cookies support.\n- [ ] Add async interface.\n- [ ] Add `multipart/form-data` support.\n- [ ] Add test client.\n- [ ] Add benchmarks.\n- [ ] Add more examples.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Artless and minimalistic web framework without dependencies, working over WSGI.",
    "version": "0.1.3",
    "project_urls": {
        "Changelog": "https://github.com/p3t3rbr0/py3-artless-framework/blob/master/CHANGELOG.md",
        "Documentation": "https://github.com/p3t3rbr0/py3-artless-framework/blob/master/README.md",
        "Homepage": "https://github.com/p3t3rbr0/py3-artless-framework",
        "Issues": "https://github.com/p3t3rbr0/py3-artless-framework/issues",
        "Repository": "https://github.com/p3t3rbr0/py3-artless-framework.git"
    },
    "split_keywords": [
        "artless",
        " minimalistic",
        " web",
        " framework"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e002de673b23913bc65834e676c035ed98c6be9a410873dda33f25cb85bded1d",
                "md5": "90cb1359c3c2c5fccd513c8936418d8e",
                "sha256": "050abb7a14ac31bb3280600fe406a10ce380a174d67b73e1639ee8f631820343"
            },
            "downloads": -1,
            "filename": "artless_framework-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "90cb1359c3c2c5fccd513c8936418d8e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 8926,
            "upload_time": "2024-08-26T08:05:15",
            "upload_time_iso_8601": "2024-08-26T08:05:15.315899Z",
            "url": "https://files.pythonhosted.org/packages/e0/02/de673b23913bc65834e676c035ed98c6be9a410873dda33f25cb85bded1d/artless_framework-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "97311ff7fc7f27d64856c41679770417a0f40b55f329d8f3c9ee5d5be66e3171",
                "md5": "834c4b49a266dbb644c30c77c2dd8f50",
                "sha256": "7eecc99d0603cb52e9fedb2d16ee24f5ec7722bc342701a0c919978a4c4f3491"
            },
            "downloads": -1,
            "filename": "artless_framework-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "834c4b49a266dbb644c30c77c2dd8f50",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 12304,
            "upload_time": "2024-08-26T08:05:17",
            "upload_time_iso_8601": "2024-08-26T08:05:17.019462Z",
            "url": "https://files.pythonhosted.org/packages/97/31/1ff7fc7f27d64856c41679770417a0f40b55f329d8f3c9ee5d5be66e3171/artless_framework-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-26 08:05:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "p3t3rbr0",
    "github_project": "py3-artless-framework",
    "github_not_found": true,
    "lcname": "artless-framework"
}
        
Elapsed time: 0.32297s