Skip to content
/ cosmo Public

A web server I'm developing in my spare time.

Notifications You must be signed in to change notification settings

Kronifer/cosmo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cosmo

Cosmo is an asynchronous python webserver that utilizes raw sockets to send and receive data, without using ASGI/WSGI.

Benchmarking

Connections Handled per Second

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...

About

A web server I'm developing in my spare time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages