Skip to main content

Dynamic JSON support for Starlette

Project description

Starlette Marshal

This package has two usage.Provide a "JSONResponse" to replace simple Starlette "JSONResponse" and works with other Python JSON libraries. And offer a "json" library to replace Python "json" library, so we can use it instead.

Installation

To install base package:

pip install -U starlette-marshal

to support RapidJSON:

pip install -U starlette-marshal[rapidjson]

or if you prefer the latest development version, you can install it from the source:

Quickstart

We want to be soft dependency. So this package is 100% compatible with standard Python and Starlette package. To archive this goal you can import it like this:

try:
    from starlette_marshal import json
except ImportError:
    import json

try:
    from starlette_marshal import JSONResponse
except ImportError:
    from starlette.responses import JSONResponse

the usage is just like Starlette itself:

async def get(request: Request) -> Response:
    content: dict = {
        'foo': 'This is foo',
        'bar': 'And here the bar',
    }
    return JSONResponse(content=content)

and for "json" library:

async def post(request: Request) -> Response:
    body: dict = json.loads(s=await request.body())
    return JSONResponse(content=body)

TODO

  • Support RapidJSON
  • Support UltraJSON
  • Support simplejson
  • Support orjson

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

starlette-marshal-0.1.0.tar.gz (7.0 kB view hashes)

Uploaded Source

Built Distribution

starlette_marshal-0.1.0-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

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