Skip to content

Service for generating documents using templates and context

License

Notifications You must be signed in to change notification settings

humangrass/docx-py

Repository files navigation

Document generation service

A microservice for generating documents using templates and transmitted context. It is easy to use, similar to Jinja2 and Django templates.

Features

  • Generate documents from templates using docxtpl
  • gRPC support for efficient communication
  • Supports text, filters, conditions, and loops within templates

Installation and Setup

Prerequisites

  1. Clone the repository:
git clone git@github.com:humangrass/docx-py.git
  1. 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
  1. 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
  1. 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
  1. Apply migrations. Make sure the database schema is up-to-date:
alembic upgrade head

Starting the gRPC Server

To start the gRPC server, run:

python app/main.py

The server will start on port 50051 by default.

Running the Client Example

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

Template Example

Below is an example of how your template might look:

img.png

Generated Document Example

Here is an example of the generated document:

img_1.png

License

This project is licensed under the MIT License.

About

Service for generating documents using templates and context

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published