Artless and minimalistic web framework without dependencies, working over WSGI.
Project description
artless-framework
The artless and minimalistic web framework without dependencies, working over WSGI.
Main principles
- Artless, fast and small (less then 1000 LOC) WSGI-framework.
- No third party dependencies (standart library only).
- Support only modern versions of Python (>=3.10).
- Integrated with most popular WSGI-servers.
- Mostly pure functions without side effects.
- Interfaces with type annotations.
- Comprehensive documentation with examples of use.
- 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
$ pip install artless-framework
Usages
from os import getenv
from artless import App, Request, Response, ResponseFactory
def say_hello(request: Request, username: str) -> Response:
return ResponseFactory.plain(f"Hello, {username}!")
def create_application(config) -> App:
app = App(config)
app.set_routes((("GET", r"^/hello/(?P<username>\w+)/$", say_hello),))
return app
config = {
"DEBUG": True,
}
application = create_application(config)
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:
$ python3 app.py
Started WSGI server on 127.0.0.1:8000
Check it:
$ curl http://127.0.0.1:8000/hello/Peter/
Hello, Peter!
See more examples.
Configureation
By default, the application defines the following config:
{
"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": "DEBUG",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
}
},
"loggers": {
"artless": {
"level": "DEBUG",
"handlers": ["stdout"],
"propagate": False,
}
},
"root": {"level": "WARNING", "handlers": ["stdout"]},
},
}
When creating an application object, override the necessary values in the config, or add new ones.
Roadmap
- Add plugin support.
- Add cookies support.
- Add async interface.
- Add
multipart/form-data
support. - Add test client.
- Add benchmarks.
- Add more examples.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
artless_framework-0.1.1.tar.gz
(10.8 kB
view hashes)
Built Distribution
Close
Hashes for artless_framework-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 360c0f04c5740d91d37bd2480c718c2fcc20607b2e2e5aaff9dda51609ddc32f |
|
MD5 | 38b6ba8c9b07a588f185322cb23fda81 |
|
BLAKE2b-256 | be88cef8a8767c0a3ac2e82f59037abd3bf1d062fca400950acb25073444b2cc |