~tsileo/gemapi

ref: a0e2c3ba666c0f985df120a9c86cff36e5916c6e gemapi/README.md -rw-r--r-- 2.3 KiB
a0e2c3baThomas Sileo Improve response handling 3 months ago

#GemAPI

builds.sr.ht status

Gemini framework written in Python.

Still in early development, there's no releases yet

#Features

  • Modern
    • as in it requires Python 3.10+
    • relies on type annotations (similar to FastAPI)
    • built on top of asyncio streams
  • Handle certificate generation and renewal
    • TLS 1.3 only with Ed25519 public key algorithm
    • Certificate is renewed automatically on expiration

#Getting started

import asyncio

from gemapi.applications import Application
from gemapi.applications import Input
from gemapi.applications import Request
from gemapi.responses import NotFoundError
from gemapi.responses import Response

app = Application()

example_dot_com_router = app.router_for_hostname("example.com")


@app.route("/")
async def index(req: Request) -> Response:
    return Response(
        status_code=20,
        meta="text/gemini",
        body="toto",
    )


@app.route("/hello/{name:str}")
async def hello(req: Request, name: str) -> Response:
    if name == "not-found":
        raise NotFoundError("nope")

    return Response(
        status_code=StatusCode.SUCCESS,
        meta="text/gemini",
        body=f"Hello {name}",
    )


    return Response(
        status_code=20,
        meta="text/gemini",
        body=f"Hello {name}",
    )


@app.route("/search")
def search(req: Request, q: Input) -> Response:
    # Also support non coroutine functions
    return Response(
        status_code=20,
        meta="text/gemini",
        body=q.get_value(),
    )


@example_dot_com_router.route("/test")
def example_dot_com__test(req: Request) -> Response:
    return Response(
        status_code=20,
        meta="text/gemini",
        body="example.com test",
    )


asyncio.run(Server(app).run())

#Contributing

All the development takes place on sourcehut, GitHub is only used as a mirror:

Contributions are welcomed.

#License

The project is licensed under the ISC LICENSE (see the LICENSE file).