A microservice for generating documents using templates and transmitted context. It is easy to use, similar to Jinja2 and Django templates.
- Generate documents from templates using
docxtpl
- gRPC support for efficient communication
- Supports text, filters, conditions, and loops within templates
- Clone the repository:
git clone git@github.com:humangrass/docx-py.git
- Ensure you have python 3.10+ installed. On UNIX systems, Python may already be installed, but make sure to have pip set up. If not, install it via the following command:
sudo apt-get install python3-pip
- Install project dependencies. It's recommended to use a virtual environment for isolation:
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
pip install -r requirements.txt
- Set up a PostgreSQL database. For ease of setup, you can use Docker and the example docker-compose.yml provided in the repository:
docker compose -f docker-compose.example.yml up -d
To stop the containers:
docker compose -f docker-compose.example.yml down
- Apply migrations. Make sure the database schema is up-to-date:
alembic upgrade head
To start the gRPC server, run:
python app/main.py
The server will start on port 50051 by default.
The client example will:
- Add a template to the database.
- Generate a document using the template and provided context.
- Remove the template after completion.
- Save the generated document as generated_document.docx.
To run the client:
python example/client.py
Below is an example of how your template might look:
Here is an example of the generated document:
This project is licensed under the MIT License.