|
1 | | -# 🚀 Document Template Processing Service 🚀 |
| 1 | +# 🚀 Document Template Processing Service |
2 | 2 |
|
3 | | -[](https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=python&logoColor=white) |
4 | | - |
5 | | -[](https://hub.docker.com/r/papihack/document-template-processor) |
6 | | -[](https://github.com/PapiHack/document-templating-service/tree/master/k8s) |
7 | | - |
8 | | - |
9 | | -[](./LICENSE) |
10 | | -[](https://github.com/ellerbrock/open-source-badges/) |
| 3 | +[](https://python.org) |
| 4 | +[](https://fastapi.tiangolo.com) |
| 5 | +[](https://hub.docker.com) |
| 6 | +[](./LICENSE) |
| 7 | +[](./docs/) |
11 | 8 |
|
12 | | -This is a simple and lightweight microservice that allow you to process your `Word` documents with a `templating system`, in order to hydrate it by injecting data or variables defined in it and get back its associated `PDF` result. |
| 9 | +A lightweight microservice for processing Word document templates with data injection and PDF conversion. Combines the power of [docxtpl](https://docxtpl.readthedocs.io/) templating with [Gotenberg](https://gotenberg.dev) PDF generation. |
13 | 10 |
|
14 | | -Feel free to checkout the [official docker image](https://hub.docker.com/r/papihack/document-template-processor) on my docker hub. |
| 11 | +## ✨ Features |
15 | 12 |
|
16 | | -## Notes |
| 13 | +- 📄 Process `.docx` templates with dynamic data |
| 14 | +- 🔄 Convert results to PDF automatically |
| 15 | +- 🚀 Fast REST API built with FastAPI |
| 16 | +- 🐳 Docker-ready with compose setup |
| 17 | +- ☸️ Kubernetes deployment manifests |
| 18 | +- 📚 Comprehensive documentation and examples |
17 | 19 |
|
18 | | -For transforming the `docx` result to `PDF` you'll need have an instance of [Gotenberg](https://gotenberg.dev) up and running and provide its `ROOT URL` as an environment variable to the microservice. |
| 20 | +## 🚀 Quick Start |
19 | 21 |
|
20 | | -## Installation |
| 22 | +```bash |
| 23 | +# Clone and start with Docker Compose |
| 24 | +git clone <repository-url> |
| 25 | +cd document-templating-service |
| 26 | +docker compose up -d |
21 | 27 |
|
22 | | -- First and foremost you'll need to have an instance of Gotenberg. You can easily have one by running the following docker command : |
| 28 | +# API will be available at http://localhost:8000/docs |
| 29 | +``` |
23 | 30 |
|
24 | | - docker run --name gotenberg -d -p 3000:3000 gotenberg/gotenberg:7 |
| 31 | +## 📖 Documentation |
25 | 32 |
|
| 33 | +- **[📋 Installation Guide](docs/installation.md)** - Complete setup instructions |
| 34 | +- **[🔧 Usage Guide](docs/usage.md)** - API documentation and templating examples |
| 35 | +- **[📑 API Docs](http://localhost:8000/docs)** - Interactive API documentation (when running) |
26 | 36 |
|
27 | | -- After this step done, you have the two (2) options in order to run this service : |
| 37 | +## 🛠️ Technology Stack |
28 | 38 |
|
29 | | - - Direct run by following the steps below : |
| 39 | +- **Backend:** FastAPI 0.115.6, Python 3.12 |
| 40 | +- **Templating:** docxtpl 0.19.0 (Jinja2-based) |
| 41 | +- **PDF Generation:** Gotenberg 8 |
| 42 | +- **Deployment:** Docker, Kubernetes |
30 | 43 |
|
31 | | - - Rename the file `.env.example` at the root level of this project by simply `.env` |
| 44 | +## 📊 Updated Dependencies (v1.1.0) |
32 | 45 |
|
33 | | - - Set the value of the `GOTENBERG_API_URL` environment variable defined in it with yours (in our example => http://localhost:3000) |
| 46 | +This version includes major dependency updates: |
| 47 | +- Python 3.8 → 3.12 |
| 48 | +- FastAPI 0.68.0 → 0.115.6 |
| 49 | +- Pydantic 1.8.2 → 2.10.3 |
| 50 | +- All dependencies updated to latest stable versions |
34 | 51 |
|
35 | | - - Install the necessary dependencies by running : |
36 | | - |
37 | | - pip install -r requirements.txt (you can create virtual env if you want it) |
| 52 | +## 🤝 Contributing |
38 | 53 |
|
39 | | - - Start the microservice by running: |
40 | | - |
41 | | - uvicorn main:app |
| 54 | +Feel free to open issues and pull requests. Please include a description with your PR. |
42 | 55 |
|
43 | | - - Visit the `API Documentation` at <http://localhost:8000/docs> or <http://localhost:8000/redoc> |
| 56 | +## 📜 License |
44 | 57 |
|
45 | | - - Using docker to build and launch a container : |
| 58 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
46 | 59 |
|
47 | | - - In your terminal, at the root of this project, build an image of this service by running : |
48 | | - |
49 | | - docker build -t document-template-processing-service . |
| 60 | +## 👨💻 Original Author |
50 | 61 |
|
51 | | - - Start the service by creating a container with : |
52 | | - |
53 | | - docker run -d -p 8000:8000 -e GOTENBERG_API_URL=your-host-ip:3000 --name dtps document-template-processing-service |
| 62 | +**[M.B.C.M (PapiHack)](https://github.com/PapiHack)** |
| 63 | +[](https://twitter.com/the_it_dev) |
54 | 64 |
|
55 | | - - An official image is also available on my [docker hub](https://hub.docker.com/r/papihack/document-template-processor), so you can simply run |
56 | | - the following command and skip the build step if you want too : |
57 | | - |
58 | | - docker run -d -p 8000:8000 -e GOTENBERG_API_URL=your-host-ip:3000 --name dtps papihack/document-template-processor |
| 65 | +--- |
59 | 66 |
|
60 | | - - Visit the `API Documentation` at <http://localhost:8000/docs> or <http://localhost:8000/redoc> |
61 | | - |
62 | | - |
63 | | -## Up & Running with Docker Compose |
64 | | - |
65 | | -If you are lazy like me 😄, you can setup the project by just running the following command : |
66 | | - |
67 | | - docker-compose up -d |
68 | | - |
69 | | -And stop all the service with : |
70 | | - |
71 | | - docker-compose stop |
72 | | - |
73 | | -Or stop and remove all the service with : |
74 | | - |
75 | | - docker-compose down |
76 | | - |
77 | | - |
78 | | -## Up & Running with Kubernetes |
79 | | - |
80 | | -If you want to deploy this project on your kubernetes cluster, you can inspect and/or edit the manifest files available in the |
81 | | -`k8s` directory before apply them. |
82 | | - |
83 | | -Start by creating the namespace named `utils` by running : |
84 | | - |
85 | | - kubectl apply -f k8s/namespace.yaml |
86 | | - |
87 | | -Then, you can deploy the necessary components by running : |
88 | | - |
89 | | - kubectl apply -f k8s/gotenberg -f k8s/document-template-processing |
90 | | - |
91 | | -After that, feel free to create an `ingress` for `svc/document-template-processing` if you are using such kind of k8s component. |
92 | | - |
93 | | -Otherwise, you can port forward the api service by running the following command before visiting <http://localhost:8000/docs> : |
94 | | - |
95 | | - kubectl port-forward svc/document-template-processing 8000:8000 -n utils |
96 | | - |
97 | | - |
98 | | -## Usage |
99 | | - |
100 | | -For now, you have an endpoint named `/api/v1/process-template-document` that will allow you to make a `POST HTTP REQUEST` by sending two (2) required parameters : |
101 | | - |
102 | | -- The `file` parameter that contains your `Word Document Template` |
103 | | - |
104 | | -- The `data` parameter that is a `JSON object` with data or variable that we are going to inject in the `file` parameter |
105 | | - |
106 | | -As a response, you'll get back its corresponding `PDF` file as a result. |
107 | | - |
108 | | -### Example |
109 | | - |
110 | | -<table> |
111 | | - <tr> |
112 | | - <th>Template Example</th> |
113 | | - <th>Postman Test Result</th> |
114 | | - </tr> |
115 | | - <tr> |
116 | | - <td><img src="./screenshots/invoice-template-doc-example.png"/></td> |
117 | | - <td><img src="./screenshots/postman-test-screenshot.png"/></td> |
118 | | - </tr> |
119 | | -</table> |
120 | | - |
121 | | -## 🚨 Cautions for Cloud Run 🚨 |
122 | | - |
123 | | -If you plan to run this on cloud, please change the `gotenberg` docker image with `gotenberg/gotenberg:7-cloudrun` or `thecodingmachine/gotenberg:7-cloudrun` in `docker-compose.yaml` file. This will allow you to save cost and so on. |
124 | | - |
125 | | -For more infos, please look at [Gotenberg Docs](https://gotenberg.dev/docs/get-started/cloud-run). |
126 | | - |
127 | | - |
128 | | -### Screenshots |
129 | | - |
130 | | - |
131 | | - |
132 | | -## Contributing |
133 | | - |
134 | | -Feel free to make a PR or report an issue 😃 |
135 | | - |
136 | | -Oh, one more thing, please do not forget to put a description when you make your PR 🙂 |
137 | | - |
138 | | -## Author |
139 | | - |
140 | | -- [M.B.C.M](https://github.com/PapiHack) |
141 | | - [](https://twitter.com/the_it_dev) |
| 67 | +> 💡 **Need help?** Check the [documentation](docs/) or open an issue! |
0 commit comments