Skip to main content

QueryFlattenMiddleware for FastAPI

QueryFlattenMiddleware is a custom middleware for FastAPI applications that flattens query parameters separated by a specified delimiter. This is particularly useful for endpoints that need to handle multiple values for the same query parameter without using the standard array format.

Features

  • Customizable Delimiter: Easily configure the delimiter used for splitting query parameter values.
  • Seamless Integration: Works as middleware within any FastAPI application.
  • Efficient Query Handling: Simplifies the process of handling multiple query parameters by flattening them, making endpoint logic cleaner and more straightforward.

Requirements

  • Python 3.8.1+
  • FastAPI

Installation

To install QueryFlattenMiddleware, you can use pip:

pip install fastapi-query-flatten

Usage

To use QueryFlattenMiddleware in your FastAPI application, simply add it as middleware in your app instance. Specify the delimiter you want to use for splitting query parameter values. The default delimiter is a comma (,).

Example

from fastapi import FastAPI
from fastapi_query_flatten import QueryFlattenMiddleware

app = FastAPI()

# Add QueryFlattenMiddleware with a custom delimiter
app.add_middleware(QueryFlattenMiddleware, delimiter=",")

With the middleware in place, a request to /items/?filter=value1,value2,value3 will be processed as if it were /items/?filter=value1&filter=value2&filter=value3, allowing the filter query parameter to be easily handled as multiple values.

Contributing

Contributions are welcome! If you have a feature request, bug report, or a pull request, please open an issue or submit a PR on the project's repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Release files for fastapi-query-flatten 0.1.2

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

Source distribution (sdist)

Source distribution for fastapi-query-flatten 0.1.2
File Size Uploaded
fastapi_query_flatten-0.1.2.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-query-flatten 0.1.2
File Interpreter ABI Platform
fastapi_query_flatten-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 6.4 kB

Release files / fastapi_query_flatten-0.1.2.tar.gz

Download URL fastapi_query_flatten-0.1.2.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a0d1422347868c5ef4d42359c6f31ef47afa1227713b3f2178c7b980c429597a
BLAKE2b-256 checksum
How to use checksums
3bfe313373343748cf87d6638ae590e501e4e7253a7ac296189c1c14f31fd0f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1019-azure

Release files / fastapi_query_flatten-0.1.2-py3-none-any.whl

Download URL fastapi_query_flatten-0.1.2-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4869eeb13e9b0a7b687a7a0fc62f93f08975023f92683309cbba16344ecc35c8
BLAKE2b-256 checksum
How to use checksums
909c2f13b063acfed5bd7c1d1b339edaccbb54b18eb91a608c99b70a87407f6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1019-azure

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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