Metadata-Version: 2.1
Name: cosmo
Version: 0.6.0
Summary: A web server implementation that uses raw sockets.
Home-page: https://github.com/kronifer/cosmo
License: Apache-2.0
Author: Kronifer
Author-email: 44979306+Kronifer@users.noreply.github.com
Requires-Python: >=3.8,<4.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Provides-Extra: uvloop
Requires-Dist: isort (>=5.10.1,<6.0.0)
Requires-Dist: loguru (>=0.5.3,<0.6.0)
Description-Content-Type: text/markdown

# 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](https://user-images.githubusercontent.com/44979306/191119603-e9b97cb1-b8dc-4cf0-8bf3-2a927dac8dac.png)

## Examples

### Simple Server

```py
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

```py
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

```py
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`:
```py
from cosmo import Request, Response, Router

router = Router()

@router.route("/")
async def index():
    return Response("<h1>Hi</h1>")
```

In `app.py`:
```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...

