Transform Ideas into PDFs, Effortlessly!
Developed with the software and tools below.
Table of Contents
The project is a robust PDF Generation API built on FastAPI, designed to streamline the creation of PDF documents from HTML content. It offers a user-friendly interface that allows users to submit requests and generate customized PDFs while ensuring secure access through API key validation. By leveraging containerization with Docker, the application ensures seamless deployment and operation, facilitating efficient scaling and management. The value proposition lies in its ability to provide high-quality, customizable document generation capabilities, making it an essential tool for developers needing to integrate PDF functionalities into their applications while maintaining a clean and organized codebase.
Feature | Description | |
---|---|---|
โ๏ธ | Architecture | A microservice architecture utilizing FastAPI for web services and asynchronous capabilities. Docker containers orchestrate the PDF generation service, enhancing deployment and scalability. |
๐ฉ | Code Quality | The codebase follows PEP 8 style guidelines with clear variable names, modular functions, and consistent formatting. It emphasizes clean code practices, improving readability and maintainability. |
๐ | Documentation | Documentation is comprehensive, detailing setup with requirements.txt , Dockerfile , and docker-compose.yml . In-line comments and structured organization guide users through the core functionalities. |
๐ | Integrations | Essential integrations include aiohttp for asynchronous HTTP requests, FastAPI for building APIs, and WeasyPrint for PDF generation. These components facilitate seamless data handling and PDF services. |
๐งฉ | Modularity | The codebase is highly modular, with separate files for routing, models, and dependencies. This structure promotes reusability and easier testing, allowing developers to update components independently. |
๐งช | Testing | Utilizes pytest for unit testing, ensuring code functionality and stability. Test cases evaluate critical paths, including API endpoints and PDF generation processes, ensuring robust performance. |
โก๏ธ | Performance | Optimized for high efficiency, the application handles multiple requests concurrently with FastAPI, minimizing response times and resource usage through asynchronous programming. |
๐ก๏ธ | Security | Employs API key validation and secure access measures. Techniques like input validation and error handling safeguard against common vulnerabilities during PDF generation. |
๐ฆ | Dependencies | Key dependencies include FastAPI, WeasyPrint, Pydantic for data validation, aiofiles for file handling, and uvicorn for running the application, ensuring robust functionality and performance. |
๐ | Scalability | Designed to scale effectively with containerization using Docker. FastAPI enables asynchronous processing, allowing the application to manage increased loads and user requests without degradation of performance. |
โโโ /
โโโ Dockerfile
โโโ README.md
โโโ app
โ โโโ __init__.py
โ โโโ dependencies.py
โ โโโ main.py
โ โโโ models.py
โ โโโ routes
โ โโโ __init__.py
โ โโโ create.py
โโโ docker-compose.yml
โโโ requirements.txt
โโโ v-gpt-pdf-generator.png
.
File | Summary |
---|---|
requirements.txt | Defines essential dependencies for the application, ensuring compatibility and functionality of key libraries. By incorporating FastAPI, WeasyPrint, and other critical packages, it enables robust web service capabilities, document generation, and efficient data handling, aligning seamlessly with the repositorys architecture to support the overall application goals. |
docker-compose.yml | Facilitates the orchestration of a PDF generation service within the repositorys architecture by defining the containerized environment. It configures essential parameters such as network settings, environment variables, and persistent storage, ensuring seamless integration and operation of the PDF generation application. |
Dockerfile | Facilitates the creation and deployment of a FastAPI application by establishing a multi-stage Docker environment. It efficiently manages Python dependencies, integrates necessary system libraries for rendering, and configures runtime parameters while ensuring the application is accessible on port 8888, aligning with the overall architecture of the repository. |
app
File | Summary |
---|---|
main.py | Facilitates the core functionality of the PDF Generation API by establishing a FastAPI application, integrating routing for PDF creation, and serving generated PDFs through a dedicated static files directory. This setup enhances the repositorys architecture by providing a scalable and organized approach to handle PDF generation requests. |
dependencies.py | Facilitates asynchronous PDF generation and cleanup tasks within the repository. It crafts customized HTML templates from content and CSS, integrates code highlighting, and manages a downloads folder by removing outdated files. Additionally, it ensures API key validation for secure access to the application. |
models.py | Defines a data model for generating PDFs, ensuring structured input through required fields like title and body content, while allowing optional custom styling and filenames. This model seamlessly integrates with the applications architecture to facilitate user-friendly PDF creation from HTML content, enhancing overall functionality. |
app.routes
File | Summary |
---|---|
create.py | Facilitates PDF generation by processing user requests and producing downloadable files. It ensures unique filename creation, integrates API key verification, and handles exceptions gracefully, enhancing the overall functionality of the application by linking user inputs with the PDF creation process effectively within the repositorys architecture. |
System Requirements:
- Python:
version 3.10
-
Download the
docker-compose.yml
file:
Save the provideddocker-compose.yml
file to your project directory. -
Edit Environment Variables:
Open thedocker-compose.yml
file and set the environment variables according to your setup:environment: BASE_URL: https://api.servicesbyv.com # Set this to your actual base URL ROOT_PATH: /pdf API_KEY: # Optional API key to connect to the API WORKERS: 1 # Number of Uvicorn workers; 1 is usually enough for personal use UVICORN_CONCURRENCY: 32 # Max connections; anything over this number is rejected
-
Run the Docker Compose:
Use the following command to start the service:docker-compose up
-
(Optional) Run in Detached Mode:
To run the containers in the background, use:docker-compose up -d
-
Access the OpenAPI Specifications:
To get the OpenAPI specifications and integrate with your AI tool, navigate to:BASE_URL/openapi.json
Replace
BASE_URL
with the actual URL of your application (e.g.,https://api.servicesbyv.com/pdf/openapi.json
).
โบ Added better default css
โบ Added title parameter to set the H1 header
โบ Added contains_code paramter to allow formatted code blocks
This project is protected under the MIT Licence