Skip to main content

ETag Middleware

Build Status Coverage

A middleware to handle ETag for Starlette or FastAPI.

Installation

pip install etag-middleware

Usage

FastAPI

from etag import ETagMiddleware
from fastapi import FastAPI
from fastapi.middleware import Middleware

app = FastAPI(middleware=[Middleware(ETagMiddleware)])

Starlette

from etag import ETagMiddleware
from starlette.applications import Starlette
from starlette.middleware import Middleware

app = Starlette(middleware=[Middleware(ETagMiddleware)])

Notice

  1. It won't compute ETag for requests with body size less than 80 bytes by default. Beacause ETag and If-None-Match increase more than 70 bytes to the response header, and computing ETag consumes CPU. You can adjust it by setting minimum_size:

    app = FastAPI(middleware=[Middleware(ETagMiddleware, minimum_size=0)])
    
  2. It won't compute ETag for StreamingResponse. Because it will delay sending the response until collected all its body and consumes more memory.

  3. It compares ETag with If-None-Match for FileResponse.

Metadata

Release files for etag-middleware 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for etag-middleware 0.2.0
File Interpreter ABI Platform
etag_middleware-0.2.0-py3-none-any.whl Python 3 none any Details

Release files / etag_middleware-0.2.0-py3-none-any.whl

Download URL etag_middleware-0.2.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aee4dd0cb9da4e15134f2d8045b964dd17062b27bb1797bd09a87232ded5c34d
BLAKE2b-256 checksum
How to use checksums
6f5d9c168012b9441826666bc25d3f3a378fc0f1fd1c5d7d2117c6ed6c50a13a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page