Skip to content

Commit 2003706

Browse files
feat: Add FastAPI service for document redlining
This commit introduces a FastAPI application to provide a web interface for the document redlining functionality. The key features of this change are: - A FastAPI application with two endpoints: - `/redline/single`: Accepts two `.docx` files and returns a single redlined document. - `/redline/double`: Accepts two `.docx` files and returns a zip archive with two redlined documents (original vs. modified and modified vs. original). - API token authentication to secure the endpoints. - A 10MB file size limit to prevent abuse. - A `Dockerfile` and `docker-compose.yml` for easy containerization and deployment. - An updated build script (`build_differ.py`) to correctly build and package the C# binaries for multiple platforms. - Comprehensive tests for the new API endpoints, including tests for authentication and file size limits. - An updated `pyproject.toml` to manage dependencies and configure the test environment. - A `.gitignore` file to exclude build artifacts and environment files. - A `.env.example` file to provide a template for setting the API token.
1 parent 254e742 commit 2003706

File tree

12 files changed

+2246
-282
lines changed

12 files changed

+2246
-282
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Generate a secure secret token, for example, by running:
2+
# python -c 'import secrets; print(secrets.token_hex(32))'
3+
API_TOKEN=your_secret_api_token_here

.gitignore

Lines changed: 25 additions & 228 deletions
Original file line numberDiff line numberDiff line change
@@ -1,236 +1,33 @@
1-
# Byte-compiled / optimized / DLL files
2-
__pycache__/
3-
*.py[cod]
4-
*$py.class
5-
6-
# C# Build Dirs
7-
csproj/bin/*
8-
csproj/obj/*
1+
# Environment variables
2+
.env
93

10-
# C extensions
11-
*.so
4+
# Python cache
5+
__pycache__/
6+
*.pyc
7+
*.pyo
8+
*.pyd
129

13-
# Distribution / packaging
14-
.Python
15-
build/
16-
develop-eggs/
17-
src/python_redlines/data/
18-
downloads/
19-
eggs/
20-
.eggs/
21-
lib/
22-
lib64/
23-
parts/
24-
sdist/
25-
var/
26-
wheels/
27-
share/python-wheels/
10+
# Build artifacts
11+
/dist/
12+
/build/
2813
*.egg-info/
29-
.installed.cfg
30-
*.egg
31-
MANIFEST
32-
33-
# PyInstaller
34-
# Usually these files are written by a python script from a template
35-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36-
*.manifest
37-
*.spec
38-
39-
# Installer logs
40-
pip-log.txt
41-
pip-delete-this-directory.txt
42-
43-
# Unit test / coverage reports
44-
htmlcov/
45-
.tox/
46-
.nox/
47-
.coverage
48-
.coverage.*
49-
.cache
50-
nosetests.xml
51-
coverage.xml
52-
*.cover
53-
*.py,cover
54-
.hypothesis/
55-
.pytest_cache/
56-
cover/
57-
58-
# Translations
59-
*.mo
60-
*.pot
61-
62-
# Django stuff:
63-
*.log
64-
local_settings.py
65-
db.sqlite3
66-
db.sqlite3-journal
67-
68-
# Flask stuff:
69-
instance/
70-
.webassets-cache
71-
72-
# Scrapy stuff:
73-
.scrapy
74-
75-
# Sphinx documentation
76-
docs/_build/
7714

78-
# PyBuilder
79-
.pybuilder/
80-
target/
81-
82-
# Jupyter Notebook
83-
.ipynb_checkpoints
84-
85-
# IPython
86-
profile_default/
87-
ipython_config.py
88-
89-
# pyenv
90-
# For a library or package, you might want to ignore these files since the code is
91-
# intended to run in multiple environments; otherwise, check them in:
92-
# .python-version
93-
94-
# pipenv
95-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
97-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
98-
# install all needed dependencies.
99-
#Pipfile.lock
100-
101-
# poetry
102-
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
103-
# This is especially recommended for binary packages to ensure reproducibility, and is more
104-
# commonly ignored for libraries.
105-
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
106-
#poetry.lock
107-
108-
# pdm
109-
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
110-
#pdm.lock
111-
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
112-
# in version control.
113-
# https://pdm.fming.dev/#use-with-ide
114-
.pdm.toml
115-
116-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117-
__pypackages__/
118-
119-
# Celery stuff
120-
celerybeat-schedule
121-
celerybeat.pid
122-
123-
# SageMath parsed files
124-
*.sage.py
125-
126-
# Environments
127-
.env
128-
.venv
129-
env/
15+
# Virtual environment
16+
.venv/
13017
venv/
131-
ENV/
132-
env.bak/
133-
venv.bak/
134-
135-
# Spyder project settings
136-
.spyderproject
137-
.spyproject
138-
139-
# Rope project settings
140-
.ropeproject
141-
142-
# mkdocs documentation
143-
/site
144-
145-
# mypy
146-
.mypy_cache/
147-
.dmypy.json
148-
dmypy.json
149-
150-
# Pyre type checker
151-
.pyre/
152-
153-
# pytype static type analyzer
154-
.pytype/
155-
156-
# Cython debug symbols
157-
cython_debug/
158-
159-
# PyCharm
160-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
161-
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
162-
163-
# User-specific stuff
164-
.idea/**/workspace.xml
165-
.idea/**/tasks.xml
166-
.idea/**/usage.statistics.xml
167-
.idea/**/dictionaries
168-
.idea/**/shelf
169-
170-
# AWS User-specific
171-
.idea/**/aws.xml
172-
173-
# Generated files
174-
.idea/**/contentModel.xml
175-
176-
# Sensitive or high-churn files
177-
.idea/**/dataSources/
178-
.idea/**/dataSources.ids
179-
.idea/**/dataSources.local.xml
180-
.idea/**/sqlDataSources.xml
181-
.idea/**/dynamic.xml
182-
.idea/**/uiDesigner.xml
183-
.idea/**/dbnavigator.xml
184-
185-
# Gradle
186-
.idea/**/gradle.xml
187-
.idea/**/libraries
188-
189-
# Gradle and Maven with auto-import
190-
# When using Gradle or Maven with auto-import, you should exclude module files,
191-
# since they will be recreated, and may cause churn. Uncomment if using
192-
# auto-import.
193-
# .idea/artifacts
194-
# .idea/compiler.xml
195-
# .idea/jarRepositories.xml
196-
# .idea/modules.xml
197-
# .idea/*.iml
198-
# .idea/modules
199-
# *.iml
200-
# *.ipr
201-
202-
# CMake
203-
cmake-build-*/
204-
205-
# Mongo Explorer plugin
206-
.idea/**/mongoSettings.xml
207-
208-
# File-based project format
209-
*.iws
210-
211-
# IntelliJ
212-
out/
213-
214-
# mpeltonen/sbt-idea plugin
215-
.idea_modules/
216-
217-
# JIRA plugin
218-
atlassian-ide-plugin.xml
219-
220-
# Cursive Clojure plugin
221-
.idea/replstate.xml
222-
223-
# SonarLint plugin
224-
.idea/sonarlint/
18+
env/
22519

226-
# Crashlytics plugin (for Android Studio and IntelliJ)
227-
com_crashlytics_export_strings.xml
228-
crashlytics.properties
229-
crashlytics-build.properties
230-
fabric.properties
20+
# IDE and editor files
21+
.idea/
22+
.vscode/
23+
*.swp
24+
*.swo
23125

232-
# Editor-based Rest Client
233-
.idea/httpRequests
26+
# Hatch
27+
/.hatch/
28+
/src/python_redlines/bin
29+
/src/python_redlines/dist
23430

235-
# Android studio 3.1+ serialized cache file
236-
.idea/caches/build_file_checksums.ser
31+
# C# build artifacts
32+
/csproj/bin/
33+
/csproj/obj/

Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.11-slim
3+
4+
# Set the working directory in the container
5+
WORKDIR /app
6+
7+
# Install .NET SDK and other dependencies
8+
RUN apt-get update && \
9+
apt-get install -y wget && \
10+
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh && \
11+
chmod +x ./dotnet-install.sh && \
12+
./dotnet-install.sh --version 8.0.100 && \
13+
rm dotnet-install.sh
14+
15+
# Add .dotnet to the PATH
16+
ENV PATH="/root/.dotnet:$PATH"
17+
18+
# Copy files required for build
19+
COPY pyproject.toml .
20+
COPY hatch_run_build_hook.py .
21+
COPY build_differ.py .
22+
COPY src/python_redlines/__about__.py src/python_redlines/__about__.py
23+
COPY csproj/ csproj/
24+
25+
# Install hatch
26+
RUN pip install hatch
27+
28+
# Build the project (which includes running build_differ.py)
29+
RUN hatch run default:build
30+
31+
# Copy the rest of the application code
32+
COPY . .
33+
34+
# Expose the port the app runs on
35+
EXPOSE 8000
36+
37+
# Start the API server
38+
CMD ["hatch", "run", "api:start"]

0 commit comments

Comments
 (0)