Skip to main content

Beautiful debugging page for Starlette apps.

Project description

Starception

Beautiful exception page for Starlette and FastAPI apps.

PyPI GitHub Workflow Status GitHub Libraries.io dependency status for latest release PyPI - Downloads GitHub Release Date Lines of code

Installation

Install starception using PIP or poetry:

pip install starception
# or
poetry add starception

Screenshot

image

Features

  • secrets masking
  • solution hints
  • code snippets
  • display request info: query, body, headers, cookies
  • session contents
  • request and app state
  • platform information
  • environment variables

The middleware will automatically mask any value which key contains key, secret, token, password.

Quick start

See example application in examples/ directory of this repository.

Usage

To render a beautiful exception page you need to install a custom error handler to your application. The error handler must be registered to Exception class or to 500 status code.

To create the handler use create_exception_handler(debug: bool) function.

Note, the handler won't do anything if debug=False, instead it will display a plain string "Internal Server Error". Also, I would recommend to add it only for local development, as such error page, when enabled on production by mistake, can expose sensitive data.

import typing

from starlette.applications import Starlette
from starlette.requests import Request
from starlette.routing import Route

from starception import create_exception_handler


async def index_view(request: Request) -> typing.NoReturn:
    raise TypeError('Oops, something really went wrong...')


app = Starlette(
    routes=[Route('/', index_view)],
    exception_handlers={Exception: create_exception_handler(debug=True)}
)

Integration with FastAPI

Create a FastAPI exception handler and register it with your app:

import typing
from fastapi import FastAPI, Request, Response
from starception import exception_handler

app = FastAPI()


@app.route('/')
async def index_view(request: Request) -> typing.NoReturn:
    raise TypeError('Oops, something really went wrong...')


def custom_exception_handler(request: Request, exc: Exception) -> Response:
    return exception_handler(request, exc, debug=True)

Solution hints

If exception class has solution attribute then its content will be used as a solution hint.

class WithHintError(Exception):
    solution = (
        'The connection to the database cannot be established. '
        'Either the database server is down or connection credentials are invalid.'
    )

image

Credentials

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starception-0.2.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

starception-0.2.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file starception-0.2.0.tar.gz.

File metadata

  • Download URL: starception-0.2.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.6 Linux/5.15.0-1014-azure

File hashes

Hashes for starception-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fd14551b5e2562b70a840a3ccf38a218dd30dfa7fbae6e6bd5a281cccb486b1d
MD5 2d1c840799a47c2ccde540663c4cc119
BLAKE2b-256 1ef3c89f9ee111b0a0584b6bc3a117ccd6be5f61fc29cf8c31a23fe40a0e06a2

See more details on using hashes here.

File details

Details for the file starception-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: starception-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.6 Linux/5.15.0-1014-azure

File hashes

Hashes for starception-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0e1ab9684958e9e26951a98f24c259a8ccd30ebdf1b1716489a3a92eb6b685a
MD5 8a97d2f4d4bd7d85081633bd8d8e8f30
BLAKE2b-256 40a7f099fa5267ce1929f29d2355ee1e9c9db0f11e95b11d477faf0cac48b8b1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page