A FastAPI-based web service for printing images from base64 data. This service accepts base64-encoded images via HTTP POST requests and sends them to the system's default printer.
- FastAPI web server with CORS support
- Accepts base64-encoded images
- Cross-platform printing support (Windows/Linux)
- Can be compiled to standalone executable using PyInstaller
- Configurable port via command line argument
- Python 3.8+
- FastAPI
- Uvicorn
- PyInstaller (for building executables)
- Install required packages:
pip install fastapi uvicorn pyinstaller
- Run the application:
python main.py --port=5050
POST /print
Send a base64-encoded image to be printed.
{
"image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA..."
}
{
"message": "Printed successfully"
}
To create a standalone executable:
pyinstaller --onefile main.py
The executable will be created in the dist/
folder.
# Linux
./dist/main --port=5050
# Windows
dist\main.exe --port=5050
The service is configured to accept requests from http://localhost:8069
. To modify this, update the allow_origins
list in the CORS middleware configuration.
- Linux: Uses
xdg-open
to open files with the default application - Windows: Uses
cmd /c start /min "" /print
to print files directly
MIT License