prez
prez copied to clipboard
Reducing dependencies
I notice Shapely is listed in the dependencies of Prez.
One big issue with having Shapely as a dependency is shapely subsequently depends on Numpy, which is a very large dependency and often needs to be compiled on installation (if the target platform does not use binary wheels).
After searching through the codebase, I see Shapely is only used in one location, that is to convert cql
->Polygon
->wkt
String.
I recently made a PR in the rdf2geojson repo to replace the use of Shapely with a vendorised copy of GeoMet. https://github.com/Kurrawong/rdf2geojson/pull/1 Note, it is vendorised so we can use it without the sub-dependency on "click", that we don't need. As well as applying some out-of-tree patches to fix multiple WKT serialization errors.
GeoMet is pure-python, is (relatively) small and is great at converting from GeoJSON to WKT and back again (and some other formats). It is compatible with the Python Geo Interface convention (__geo_interface__
) so should work for our use case in Prez.
Secondly, uvicorn
is included as a non-optional requirement in the dependencies list. Again, the main issue is the sub-dependency on uvloop
that again is a rather large dependency that also often needs to be compiled on installation (if the target platform does not use binary wheels).
Those who are familiar with the codebase will know that uvicorn
is used in exactly one place in the codebase, that is at the bottom of main.py
, if you are running prez
as a standalone application it will spawn uvicorn
to run the app.
There are lots of other ways of running the FastAPI ASGI app other than uvicorn (eg, in a Azure Function App, a AWS Lambda app, Apache ASGI wrapper, another ASGI runner like hypercorn or daphne). So I believe uvicorn
should be an optional dependency, because not everyone is going to want Prez to supply its own server.
The motivation for these changes is to reduce the size of the requirements.txt
file generated by poetry:
poetry export --format=requirements.txt > requirements.txt"
This is used when generating the requirements for building the Azure Function App bundle, and I feel the total built bundle size could be smaller.