This is a simple project I created to showcase some basic functionality of FastAPI, and because I got tired of searching for reliable and free ways of working with PDF files, especially because the files contained some sensitive information.
I created this, so it would work fine in my home lab setup, but anyone can use it (at least the PDF endpoints).
It comes with docker support to make it easier to use. In the docker image, the port used is 6006
, and if you run it
locally, it's port 8000
. I changed the swagger address to /api/docs
(so, http://localhost:8000/api/docs
).
GET '/api/v1/health'
: Health check endpoint. Returns 200 if the service is up and running.GET '/api/v1/sys-mon'
: Returns the system's CPU and memory usage.POST '/api/v1/notify
: If the request body contains amsg
field, a message will be sent to the/alerts/info
MQTT queue.POST /api/v1/pdf/compress
: Compresses a PDF file. The file must be sent as a form-data field namedfile
.POST /api/v1/pdf/split
: Splits a PDF file. The file must be sent as a form-data field namedfile
.POST /api/v1/pdf/merge
: Merges multiple PDF files.
Some endpoints will not be available, depending on your configuration. PDF endpoints are always available.
In the docker folder there's a Dockerfile that can be used to build the image. I also provided two scripts:
build.sh
: Builds the image, exposing port6006
.run.sh
: Runs the image, configuring all endpoints. It will expose the port6006
.run_pdf_only.sh
: Runs the image, but only the PDF endpoints will be available. It will expose the port6006
.
The run command has some weird volumes set up because the system monitor uses them to get info from the host. It's all read-only, so it's safe-ish to use.
You'll need to install Ghostscript
- Windows: https://ghostscript.com/releases/gsdnld.html
- Linux:
sudo apt-get update && sudo apt-get install -y ghostscript
and you'll need to set the following environment variables:
MQTT_HOST
: The MQTT broker host. Defaults tolocalhost
.MQTT_PORT
: The MQTT broker port. Defaults to1883
(optional. Defaults to 1883).LOCAL_DISK_PATH
: The path to the local disk.NAS_PATH
: The path to the NAS.
Variables related to MQTT are pretty specific to my setup, so this endpoint won't do anything for anyone else. (sorry about that) Without 'LOCAL_DISK_PATH' and 'NAS_PATH' the system monitor won't work.
The PDF endpoints will work regardless of the environment variables.
Starting from version 1.1.0
, if you don't configure MQTT or the required paths, the API will work normally, but will
hide the unavailable endpoints. This is a bit hacky, but will make for a better experience, in case anyone else wants
to use this.