Metadata-Version: 2.3
Name: pinta_backend
Version: 0.1.0
Summary: Add your description here
Requires-Dist: fastapi
Requires-Dist: uvicorn
Requires-Dist: pydantic-settings
Requires-Dist: apache-airflow-client==3.3.1
Requires-Dist: httpx
Requires-Dist: jsonschema
Requires-Dist: pinta-db[psycopg]>=0.2.0,<0.3
Requires-Dist: pinta-lib
Requires-Python: >=3.12, <3.14
Description-Content-Type: text/markdown

# Pinta backend

## Development

By default, run the backend in a container from the repository root with Docker
Compose:

```bash
docker compose up -d
```

This also starts the Airflow container the backend depends on. Make sure that you have
setup Airflow connection configuration from .env.example to your .env.

The backend listens on `http://localhost:3011` by default and runs with uvicorn
live reload enabled. Override the host port with `COMPOSE_BACKEND_PORT`:

Verify that the API works:

```bash
curl http://localhost:3011/health
```

The health response includes a `versions` object containing the keys and values
from `/opt/pinta/version.json`. On installed hosts, Ansible writes this file.
Set `PINTA_BACKEND_VERSION_DIR` to change its containing directory. If the file
is missing or invalid, `versions` is empty and dependency health is unchanged.

For local development, `make up`, `make up-backend`, and `make backend-start`
generate a root-level `version.json` from component `pyproject.toml` versions.
Compose mounts it at `/opt/pinta/version.json`; the host-run backend reads it
from the repository root. Before using `docker compose up` directly, run
`make generate-versions`. Local `processing_image_tag` and `backend_image_tag`
are package versions, not Docker image tags; `db_version` is the package
version, not an Alembic revision. The backend returns all file values as-is.

or play with the API manually with [requests.http](requests.http) file.

If health shows DOWN for Airflow, make sure that you have Airflow running. The backend authenticates against Airflow using `PINTA_BACKEND_AIRFLOW_USERNAME` / `PINTA_BACKEND_AIRFLOW_PASSWORD` from `.env`.

### Local development

Optionally run the backend directly on the host from the repository root:

```bash
make backend-start
# If you want to use local airflow as well:
# make airflow-start
```

This stops the Compose backend container first, so the local process can bind to
port 3011. From this directory, the equivalent local command is
`python -m pinta_backend`.

## Swagger

FastAPI serves the interactive Openapi spec at
`http://localhost:3011/docs`.

## Building the container

Build targets:

| Target | Package source | Usage |
| --- | --- | --- |
| `dev` | Local repository source | Used by Docker Compose for backend development. Tagged as latest and build from main branch. |
| `prod` | Published PyPI package | Used for release images. Build requires `PINTA_BACKEND_VERSION` and `PINTA_BACKEND_CONSTRAINT`. |

Build a production image with:

```bash
VERSION=0.3.1
uv pip install --no-deps --target /tmp/pinta-backend "pinta_backend==$VERSION"
mkdir -p .release-constraints
cp /tmp/pinta-backend/pinta_backend/constraints.txt .release-constraints/pinta_backend.txt

docker build \
  --target prod \
  -f components/backend/Containerfile \
  --build-arg "PINTA_BACKEND_VERSION=$VERSION" \
  --build-arg PINTA_BACKEND_CONSTRAINT=.release-constraints/pinta_backend.txt \
  --build-arg PYPI_INDEX_URL=https://pypi.example.invalid/simple \
  -t "ghcr.io/nlsfi/pinta/pinta-backend:$VERSION" \
  .
```

Image tags:

* `latest` is the nightly build from the `main` branch.
* Version tags are release builds from tagged versions, published as both `backend:<version>` and `pinta-backend:<version>`.

## Translations

The API is localized using the `Accept-Language` request header. The response language is defined in the `Content-Language` response header.

Translate texts with:

```python
from pinta_backend.i18n import _

translated_string = _("Foo")
```

Currently, translations are not automatically updated if the translator is imported using a symbol other than `_`.

### Updating translations

* Update translation files from the repository root with `make backend-ts`, or from this directory with `./src/pinta_backend/scripts/update-translations.sh`
* Update translations in the language-specific `.po` files
* Compile translations from the repository root with `make backend-tc`, or from this directory with `./src/pinta_backend/scripts/compile-translations.sh`

Initialize new languages with:

```bash
msginit --input=<path to .pot> --locale=<locale code> --output-file=<path to output .po>
```
