# artless-core
![PyPI Version](https://img.shields.io/pypi/v/artless-core)
![Development Status](https://img.shields.io/badge/status-3%20--%20Alpha-orange)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/artless-core)
[![Downloads](https://static.pepy.tech/badge/artless-core)](https://pepy.tech/project/artless-core)
![PyPI - License](https://img.shields.io/pypi/l/artless-core)
The artless and minimalistic web library for creating small applications or APIs.
## Motivation
An extremely minimalistic framework was needed to create the same minimalistic applications. Those "micro" frameworks like `Flask`, `Pyramid`, `CherryPie`, etc - turned out to be not micro at all). Even a single-module `Bottle` turned out to be a "monster" of 4 thousand LOC and supporting compatibility with version 2.7.
Therefore, it was decided to sketch out our own simple, minimally necessary implementation of the WSGI library for creating small/simple web app.
## Main principles
1. Artless, fast and small (less then 400 LOC) single-file module.
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 `Async/ASGI` support.
* No `WebSocket` support.
* No `Cookies` support.
* No `multipart/form-data` support.
* No built-in protections, such as: `CSRF`, `XSS`, `clickjacking` and other.
## Installation
``` shellsession
$ pip install artless-core
```
## Getting Started
``` python
from http import HTTPStatus
from os import getenv
from artless import App, Request, Response, ResponseFactory
def get_template(username: str) -> str:
return f"""
<!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(get_template(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"}
```
Need more? See [documentation](https://pages.peterbro.su/py3-artless-core/) and [examples](https://git.peterbro.su/peter/py3-artless-core/src/branch/master/examples).
## Roadmap
- [ ] Add Async/ASGI support.
- [ ] Add plugin support.
- [ ] Add cookies support.
- [ ] Add `multipart/form-data` support.
- [ ] Add test client.
- [ ] Add benchmarks.
- [ ] Add more examples.
- [x] Add Sphinx doc.
## Related projects
* [artless-template](https://pypi.org/project/artless-template/) - the artless and small template library for server-side rendering.
Raw data
{
"_id": null,
"home_page": null,
"name": "artless-core",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "artless, minimalistic, http, wsgi, web, library, framework",
"author": null,
"author_email": "Peter Bro <p3t3rbr0@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/c7/84/1f386c12e1a9aacdbe96971ff68c54269c59d6c89415858418143af1ef81/artless_core-0.2.1.tar.gz",
"platform": null,
"description": "# artless-core\n\n![PyPI Version](https://img.shields.io/pypi/v/artless-core)\n![Development Status](https://img.shields.io/badge/status-3%20--%20Alpha-orange)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/artless-core)\n[![Downloads](https://static.pepy.tech/badge/artless-core)](https://pepy.tech/project/artless-core)\n![PyPI - License](https://img.shields.io/pypi/l/artless-core)\n\nThe artless and minimalistic web library for creating small applications or APIs.\n\n## Motivation\n\nAn extremely minimalistic framework was needed to create the same minimalistic applications. Those \"micro\" frameworks like `Flask`, `Pyramid`, `CherryPie`, etc - turned out to be not micro at all). Even a single-module `Bottle` turned out to be a \"monster\" of 4 thousand LOC and supporting compatibility with version 2.7.\n\nTherefore, it was decided to sketch out our own simple, minimally necessary implementation of the WSGI library for creating small/simple web app.\n\n## Main principles\n\n1. Artless, fast and small (less then 400 LOC) single-file module.\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 `Async/ASGI` support.\n* No `WebSocket` support.\n* No `Cookies` support.\n* No `multipart/form-data` support.\n* No built-in protections, such as: `CSRF`, `XSS`, `clickjacking` and other.\n\n## Installation\n\n``` shellsession\n$ pip install artless-core\n```\n\n## Getting Started\n\n``` python\nfrom http import HTTPStatus\nfrom os import getenv\n\nfrom artless import App, Request, Response, ResponseFactory\n\n\ndef get_template(username: str) -> str:\n return f\"\"\"\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\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(get_template(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<!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\nNeed more? See [documentation](https://pages.peterbro.su/py3-artless-core/) and [examples](https://git.peterbro.su/peter/py3-artless-core/src/branch/master/examples).\n\n## Roadmap\n\n- [ ] Add Async/ASGI support.\n- [ ] Add plugin support.\n- [ ] Add cookies support.\n- [ ] Add `multipart/form-data` support.\n- [ ] Add test client.\n- [ ] Add benchmarks.\n- [ ] Add more examples.\n- [x] Add Sphinx doc.\n\n## Related projects\n\n* [artless-template](https://pypi.org/project/artless-template/) - the artless and small template library for server-side rendering.\n",
"bugtrack_url": null,
"license": null,
"summary": "The artless and minimalistic web library for creating small applications or APIs.",
"version": "0.2.1",
"project_urls": {
"Changelog": "https://github.com/p3t3rbr0/py3-artless-core/blob/master/docs/source/changelog.rst",
"Documentation": "https://github.com/p3t3rbr0/py3-artless-core/blob/master/README.md",
"Homepage": "https://github.com/p3t3rbr0/py3-artless-core",
"Issues": "https://github.com/p3t3rbr0/py3-artless-core/issues",
"Repository": "https://github.com/p3t3rbr0/py3-artless-core.git"
},
"split_keywords": [
"artless",
" minimalistic",
" http",
" wsgi",
" web",
" library",
" framework"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "da52f2ab9e49792acb1550b31107c21fa249146521a5865d71759d67a3ce3e19",
"md5": "4f597e464abeab4a72479f121f559a32",
"sha256": "771d9e812a2aa03b6b37f2dfdac01e5672d8e9a6376cff3c91c6c91b32c5bf17"
},
"downloads": -1,
"filename": "artless_core-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4f597e464abeab4a72479f121f559a32",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 7867,
"upload_time": "2024-10-27T16:08:15",
"upload_time_iso_8601": "2024-10-27T16:08:15.933769Z",
"url": "https://files.pythonhosted.org/packages/da/52/f2ab9e49792acb1550b31107c21fa249146521a5865d71759d67a3ce3e19/artless_core-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c7841f386c12e1a9aacdbe96971ff68c54269c59d6c89415858418143af1ef81",
"md5": "a8959da2c89ec5d73ff5c8b6323f1d66",
"sha256": "a8d3dd62da6a5cb6c4a76b23e553eb5c4fce68a43ca4e04045c27d6fabcb7d85"
},
"downloads": -1,
"filename": "artless_core-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "a8959da2c89ec5d73ff5c8b6323f1d66",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 11157,
"upload_time": "2024-10-27T16:08:17",
"upload_time_iso_8601": "2024-10-27T16:08:17.228103Z",
"url": "https://files.pythonhosted.org/packages/c7/84/1f386c12e1a9aacdbe96971ff68c54269c59d6c89415858418143af1ef81/artless_core-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-27 16:08:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "p3t3rbr0",
"github_project": "py3-artless-core",
"github_not_found": true,
"lcname": "artless-core"
}