0.6.0 (Unreleased)

This the first major release of Expanse which includes several new features and improvements

HTTP sessions

HTTP sessions support has been added with multiple stores supported out of the box, including database, file and in-memory stores. Redis support is planned for a future release.

from expanse.http.request import Request
from expanse.http.response import Response


class MyController:

    async def index(self, request: Request) -> Response:
        session = request.session
        value = session["key"]

        ...

You can learn more about http sessions in the documentation.

Route declaration via decorators

You can now declare routes directly in your controllers via decorators:

from expanse.contracts.routing.registrar import Registrar
from expanse.routing.helpers import get


@get("/hello", name="hello")
def say_hello() -> str:
    return "Hello world!"


def routes(router: Registrar) -> None:
    router.handler(say_hello)

You can use them on controllers as well as on standalone functions.

from expanse.contracts.routing.registrar import Registrar
from expanse.http.response import Response
from expanse.routing.helpers import get


class ArticleController:
    @get("/articles", name="articles.index")
    def index(self) -> Response:
        ...


def routes(router: Registrar) -> None:
    router.controller(ArticleController)

Encrypted cookies

All cookies will now be encrypted by default, thanks to the new EncryptCookies middleware, so that they can't be neither read nor tampered with by the client. If you would like to disable encryption for specific cookies, you can do so when configuring the middleware:

from expanse.http.middleware.encrypt_cookies import EncryptCookies
from expanse.core.http.middleware.middleware_stack import MiddlewareStack


async def configure_middleware(middleware: MiddlewareStack):
    middleware.group("web").replace(
        EncryptCookies,
        EncryptCookies.excluding("cookie_name", "other_cookie")
    )

Improved encryption

The encryption system has been improved:

  • It's now possible to rotate encryption keys.
  • The key derivation salt will now be generated via the encryption generate key command.
  • Messages can now be loaded directly from an encrypted string

Improved performance

Performance has been vastly improved by optimizing several internal components, including the routing system and the response system which has been rewritten from scratch.