litestar icon indicating copy to clipboard operation
litestar copied to clipboard

Enhancement: Slim down minimum required dependencies

Open provinzkraut opened this issue 2 years ago • 7 comments

Summary

Ideally we want the base litestar package to have as few dependencies as possible. Right now we install a lot of extra packages that aren't actually needed for the core functionality. These fall roughly into two groups: Speedups and additional features.

Speedups include:

  • fast-query-parsers (#2394)
  • multidict

Additional features:

  • pyyaml to support exporting the OpenAPI schema as YAML
  • httpx for the TestClient
  • polyfactory to generate OpenAPI examples (#2390)

Libraries required for Litestar to work

  • anyio
  • msgspec

The goal would be to exclude everything that's not strictly necessary from the base install and make it available through package extras, which could be included in the standard extra as well. This is a common practice and is used by packages like uvicorn, starlette and fastapi.


The plan is to work on these without breaking anything, and removing the packages as required dependencies once we hit 3.0.

Basic Example

No response

Drawbacks and Impact

No response

Unresolved questions

No response


Funding

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
Fund with Polar

provinzkraut avatar Oct 03 '23 08:10 provinzkraut

I find it a bit strange that fast-query-parsers is included only with [standard], but standard also includes jinja2.

But jinja2 is quite bloated and makes no sense for a JSON API (the typical use case of litestar I guess), so installing standard is not a good idea if you only need a JSON API. But then fast-query-parsers has to be installed manually.

Currently, I'm installing it via:

litestar[sqlalchemy,cli] 
fast-query-parsers

hyperknot avatar Oct 09 '23 14:10 hyperknot

Some more data in https://github.com/litestar-org/litestar/issues/2844

JacobCoffee avatar Dec 08 '23 00:12 JacobCoffee

mashumaro supports both yaml and messagepack, not sure about yaml version or efficiency tho

rafalkrupinski avatar May 16 '24 11:05 rafalkrupinski

mashumaro supports both yaml and messagepack, not sure about yaml version or efficiency tho

Nsgspec also support both JSON, YAML and MessagePack, as we already using it, and it is performant.

FHU-yezi avatar May 16 '24 14:05 FHU-yezi

In that case is pyYAML still necessary?

rafalkrupinski avatar May 16 '24 16:05 rafalkrupinski

msgspec supports yaml via pyYAML.

Is this conversation really relevant to this issue? If you want to suggest changing the serialization library we support that should be in its own ticket.

peterschutt avatar May 16 '24 16:05 peterschutt

Relevant but invalid. I thought Mashumaro supported YAML natively, in which case it would allow you to get rid of one dependency, but it doesn't.

rafalkrupinski avatar May 16 '24 17:05 rafalkrupinski