- Installation (Python 3.12) using PDM
- Using Docker
- Using docker compose (recommended for local multi-service setup)
- Update dependencies locally
- Add new package
- Docker image
- Install Platform.sh CLI
- Run Locally
- Profiling locally with Blackfire
- Production Deployment
pdm venv create 3.12
pdm use
pdm venv activate
pdm sync --dev
wget -P training_data https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin- Install Docker engine - https://docs.docker.com/engine/install/
- Start LanguageTool from Docker Hub (erikvl87/languagetool):
# Create an isolated network so containers can talk by name
docker network create nlp-net
# Start LanguageTool on port 8010
docker run -d --name lt --network nlp-net -p 8010:8010 erikvl87/languagetool:latestLanguageTool API will be available at http://localhost:8010/v2
- Build and run the NLP API locally:
# Build the API image from the local Dockerfile
docker build -t nlpapi .
# Run the API and point it to the LanguageTool container
docker run -d --name nlp_api --network nlp-net -p 8080:8080 \
-e LANGUAGETOOL_API=http://lt:8010/v2 \
nlpapiYou should see the application running under http://localhost:8080/docs
A ready-made compose.yml is included to start both the NLP API and LanguageTool with one command. It:
- Launches
erikvl87/languagetoolon port8010 - Builds and runs the API on port
8080 - Mounts your local
./modelsdirectory read-only into the container (so local SetFit models can be used if present) - Sets
LANGUAGETOOL_APIinside the API container to point to the LanguageTool service
Quick start:
# Start both services in the background
docker compose up -d
# Check health
curl http://localhost:8080/health
# Visit http://localhost:8080/docs in your browserEnable local context checker models (if you downloaded them):
# Option 1: temporarily set env when starting
CONTEXT_CHECKER_LOCAL=true docker compose up -d
# Option 2: uncomment CONTEXT_CHECKER_LOCAL in compose.yml and re-runUpdating models: any changes you make in ./models on the host are reflected in the container because of the bind mount. The mount is read-only (:ro) to prevent accidental writes from inside the container.
Stop and remove services:
docker compose downRebuild after code changes (forces image rebuild):
docker compose build --no-cache nlpapi
docker compose up -dTail logs:
docker compose logs -f nlpapi
docker compose logs -f languagetoolIf you only need the API without LanguageTool, you can still use the single-container commands above or remove the languagetool service from the compose file.
To update packages locally after pyproject.toml/pdm.lock was changed:
pdm sync --devWhen adding a new package to the project, update pyproject.toml via:
pdm add <package_name>After making changes in the code or in the Dockerfile, build a fresh image:
pdm export --prod -o requirements.txt
DOCKER_BUILDKIT=0 docker build -t nlpapi . --no-cache
docker run nlpapi- Run
platform login - Run
platform project:set-remote - Run
platform listto find out what commands are available - Run
platform help [command]to find out details about a command
See https://docs.platform.sh/development/cli.html for details
Adjust server size:
platform e:curl -e main /deployments/next -X PATCH -d '{"webapps":
{"app": {"resources": {"profile_size": "8"}},"languagetool": {"resources": {"profile_size": "4"}}}}'Adjust instance count:
platform e:curl -e main /deployments/next -X PATCH -d '{"webapps":
{"app": {"resources": {"instance_count": "2"}},"languagetool": {"resources": {"instance_count": "2"}}}}'Note for Mac users. Set environment variables with the following snippet:
cp .env.development.mac .envStart the dev server:
pdm run uvicorn app.main:app --reloador
uvicorn app.main:app --reloadOpen your browser to http://localhost:8000/docs to view the OpenAPI UI.
Alternative docs: http://localhost:8000/redoc
pdm run blackfire-python uvicorn app.main:app --reloadMake sure you have a .blackfire.ini, get the settings from
https://blackfire.io/docs/php/configuration
BLACKFIRE_SERVER_ID=""
BLACKFIRE_SERVER_TOKEN=""Set an env variable API_DOCS_AUTH_ENABLED to "true" and set API_DOCS_USERNAME and API_DOCS_PASSWORD for basic auth for the API docs.
If the build fails due to "No space left on device" while installing dependencies run:
platform project:clear-build-cacheSee: https://docs.platform.sh/development/troubleshoot.html#clear-the-build-cache
- Configuration & Environment Variables - Environment setup and configuration options
- API Endpoints - Available endpoints and authentication
- Technical Notes - Architecture and implementation details
- Back to 📋 Documentation Index