A high-level web server with fine tuned low-level control.
Project description
Cosmo
Cosmo is an asynchronous python webserver that utilizes raw sockets to send and receive data, without using ASGI/WSGI.
Benchmarking
Examples
Simple Server
from cosmo import App, Request, Response
app = App("0.0.0.0", 8080)
@app.route("/", "text/html")
async def index(request: Request):
return Response(f"<h1>{request.address}</h1>")
app.serve()
Using Custom Headers
from cosmo import App, Request, Response
app = App("0.0.0.0", 8080)
@app.route("/", "text/html")
async def index(request: Request):
headers = {"x-custom-header": "custom"}
content = "<h1>Custom Headers: </h1>\n<ul>"
for header in headers.keys():
content += f"<li>{header}: {headers[header]}</li>\n"
content += "</ul>"
return Response(content, headers)
app.serve()
Returning an HTML Page
from cosmo import App, html_page, Request, Response
app = App("0.0.0.0", 8080)
@app.route("/", "text/html")
async def index(request: Request):
return Response(html_page("path/to/page.html"))
app.serve()
Using Routes from a different file
In router.py:
from cosmo import Request, Response, Router
router = Router()
@router.route("/")
async def index():
return Response("<h1>Hi</h1>")
In app.py:
from cosmo import App, Request, Response
from router import router
app = App("0.0.0.0", 8080)
app.import_router(router)
app.serve()
Docs
Coming soon...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cosmo-0.7.0.tar.gz
(6.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
cosmo-0.7.0-py3-none-any.whl
(8.1 kB
view details)
File details
Details for the file cosmo-0.7.0.tar.gz.
File metadata
- Download URL: cosmo-0.7.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.8 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af78c38ea36c59cc4c1c3ff197948907e2a97d485df13b88307ffe7a1fc8d83c
|
|
| MD5 |
842e4c9cb57e9c0495d5a6c05cfe8e17
|
|
| BLAKE2b-256 |
568c465a85e1775b0b1744c871f235b9001d191859bf6a317a5d47ddc7dc10af
|
File details
Details for the file cosmo-0.7.0-py3-none-any.whl.
File metadata
- Download URL: cosmo-0.7.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.8 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e624ad495cabed12208dcfde8362e727db82ab8d5484375d787b7652392e4c43
|
|
| MD5 |
f0a55122dadf9d5f3287f191d3f9790f
|
|
| BLAKE2b-256 |
ac87e7ebe2f81b618cc466ce8c39d2781c0e7cd1ac63decf2486dddf8b346dbf
|