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 StarceptionMiddleware middleware to your application.

The middleware will work only in debug mode so don't forget to set debug=True for local development.

Note, to catch at many exceptions as possible the middleware has to be the first one in the stack.

import typing

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

from starception import StarceptionMiddleware


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


app = Starlette(
    debug=True,
    routes=[Route('/', index_view)],
    middleware=[
        Middleware(StarceptionMiddleware),
        # other middleware go here
    ],
)

Integration with FastAPI

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

import typing

from fastapi import FastAPI, Request

from starception import StarceptionMiddleware

app = FastAPI(debug=True)
app.add_middleware(StarceptionMiddleware)  # must be the first one!


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

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.3.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

starception-0.3.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: starception-0.3.0.tar.gz
  • Upload date:
  • Size: 10.7 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.3.0.tar.gz
Algorithm Hash digest
SHA256 978b0a06992cbf66f8778db8a99f209220ae15b106bf5ad43e967f61b9929040
MD5 f7103223ebc75a9f58951c036648a55d
BLAKE2b-256 7be7092207126fd2d4acff0e2a82c7aab7ed94b853ccc590aacaf3358d87bb47

See more details on using hashes here.

File details

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

File metadata

  • Download URL: starception-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67c6cdd85deb67357caefe41a44fccbe68fdd2d899687a04ac0ed9f9c317f4eb
MD5 7ead567fa64eb4c432be6af062aed0e2
BLAKE2b-256 91ad6cb9acc4cef69a38ba61fe68dfebb82b1697e2e4fec1f6241606a2f5774f

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