Skip to content

Application settings

Environment variables tell HERITRACE where its databases are, who its administrators are, how to sign users in and which Python components to load. The title, the data model, the deletion rules and the other settings live in the configuration folder. Administrators edit them in the app, as described in Configuration editor.

Set the variables in your docker-compose.yml file, or in a .env file:

environment:
# Security (REQUIRED: Change this!)
- SECRET_KEY=your-secure-secret-key-here
# Configuration folder and administrators
- CONFIG_DIR=/app/config
- ADMIN_ORCIDS=0000-0002-1825-0097
# Base of the IRIs of new entities
- BASE_IRI=https://example.org/my-collection
# Database endpoints
- DATASET_DB_URL=http://dataset-db:8890/sparql
- PROVENANCE_DB_URL=http://provenance-db:8890/sparql
- DATASET_DB_TRIPLESTORE=virtuoso
- PROVENANCE_DB_TRIPLESTORE=virtuoso
- DATASET_IS_QUADSTORE=true
- PROVENANCE_IS_QUADSTORE=true
# ORCID authentication
- ORCID_CLIENT_ID=your-client-id
- ORCID_CLIENT_SECRET=your-client-secret
Environment VariableTypeDescriptionRequiredDefault
SECRET_KEYStringFlask secret key that signs the session cookiesYesNone
FLASK_ENVStringdemo signs every visitor in as the demo user http://example.org/demo/demo_user, without ORCID. development and production require ORCIDNodevelopment
FRONTEND_ORIGINSStringOrigins of web clients served from other addresses, separated by spaces, such as https://127.0.0.1:5100 https://192.168.1.177:5100. HERITRACE accepts requests with cookies from each of them and, after sign-in, returns to the one the user came fromNoNone
Environment VariableTypeDescriptionRequired
CONFIG_DIRPathFolder that holds the configuration. A relative path starts from the HERITRACE folderYes

The folder holds settings.db with the system settings and shacl.ttl with the entity types. HERITRACE needs only settings.db, which setup mode creates on the first start. Where the configuration lives describes each file.

The configuration editor rewrites the files when you save, so HERITRACE must be able to write to the folder. In Docker, mount the folder:

services:
web:
environment:
- CONFIG_DIR=/app/config
volumes:
- ./config:/app/config

When the folder has no valid configuration, HERITRACE starts in setup mode and waits for an administrator to provide one. See Setup mode.

ADMIN_ORCIDS lists the ORCID iDs of the administrators, separated by commas. You can write each one as a bare iD or as a full ORCID URL.

environment:
- ADMIN_ORCIDS=0000-0002-1825-0097,https://orcid.org/0000-0001-5109-3700

Administrators can always sign in, even when they are missing from the list of authorized ORCID iDs in the system settings. Only they see the configuration editor.

Both development and production environments use Gunicorn as the WSGI server. The number of workers and request timeout are configurable.

environment:
- GUNICORN_WORKERS=4
- GUNICORN_TIMEOUT=120
Environment VariableTypeDescriptionDefault
GUNICORN_WORKERSIntegerNumber of Gunicorn worker processes(2 * CPU cores) + 1
GUNICORN_TIMEOUTIntegerMaximum seconds a worker can spend handling a single request before being restarted120

In production, Gunicorn serves plain HTTP. Use a reverse proxy (e.g., nginx) to terminate HTTPS. In development, Gunicorn serves HTTPS directly using a self-signed certificate generated on first startup.

HERITRACE uses Redis for counter management and caching. You can use either an internal Redis instance (default) or connect to an external Redis server.

By default, HERITRACE runs a Redis instance inside the application container. No additional configuration is needed.

HERITRACE keeps its counters there: the number of the next IRI and the number of the next provenance version of each entity. It updates them on every change. On its first start, and whenever Redis has lost the counters, HERITRACE rebuilds them by reading the databases.

If you add data to the databases without going through HERITRACE, the counters fall behind, and HERITRACE could create an IRI that already exists. Ask HERITRACE to rebuild them at the next start:

Terminal window
docker compose exec web redis-cli DEL heritrace:counters_initialized

To use an external Redis instance, set the REDIS_URL environment variable:

environment:
- REDIS_URL=redis://heritrace-redis:6379/0

HERITRACE skips counter initialization when it uses an external Redis instance, so make sure the counters are already there.

Environment VariableTypeDescriptionRequiredDefault
REDIS_URLStringConnection URL for external Redis serverNoredis://localhost:6379/0 (internal)

Compatible with SPARQL 1.1 triplestores. Tested with Virtuoso, Blazegraph and QLever.

environment:
# Triplestore types
- DATASET_DB_TRIPLESTORE=virtuoso
- PROVENANCE_DB_TRIPLESTORE=virtuoso
# Database URLs
- DATASET_DB_URL=http://dataset-db:8890/sparql
- PROVENANCE_DB_URL=http://provenance-db:8890/sparql
# Storage types
- DATASET_IS_QUADSTORE=true
- PROVENANCE_IS_QUADSTORE=true
# Full-text search
- DATASET_DB_TEXT_INDEX_ENABLED=true
Environment VariableOptionsDescription
DATASET_DB_TRIPLESTOREvirtuoso, blazegraph, qleverType of the dataset database
PROVENANCE_DB_TRIPLESTOREvirtuoso, blazegraph, qleverType of the provenance database
DATASET_DB_URLURLSPARQL endpoint of the dataset database
PROVENANCE_DB_URLURLSPARQL endpoint of the provenance database
DATASET_IS_QUADSTOREtrue/falseEnable named graph support
PROVENANCE_IS_QUADSTOREtrue/falseEnable provenance named graphs
DATASET_DB_TEXT_INDEX_ENABLEDtrue/falseSearch for existing entities with the full-text index of the dataset database
environment:
- DATASET_DB_TRIPLESTORE=virtuoso
- PROVENANCE_DB_TRIPLESTORE=virtuoso

Pros:

  • Mature and battle-tested database
  • Open source and SPARQL 1.1 compliant
  • Good performance with large datasets
  • Full-text indexing and named graph support

Cons:

  • Complex configuration
  • Poor documentation
Visit the Virtuoso GitHub Repository

Three environment variables select Python classes that HERITRACE loads at start. A matching _OPTIONS variable holds a JSON object, whose properties HERITRACE passes to the class constructor as keyword arguments. An _OPTIONS variable needs its _CLASS variable.

Environment VariableDescriptionDefault
URI_GENERATOR_CLASS, URI_GENERATOR_OPTIONSCreates the IRIs of new entitiesThe built-in generator
COUNTER_HANDLER_CLASS, COUNTER_HANDLER_OPTIONSStores the counters of counter-based IRI generatorsA counter handler in Redis
SAVE_PLUGIN_CLASS, SAVE_PLUGIN_OPTIONSReceives each change after HERITRACE writes it to the databasesNone
BASE_IRIBase IRI of the built-in IRI generatorNone

Each class is given by its import path, such as default_components.meta_uri_generator.MetaURIGenerator.

The default_components/ directory holds ready-made components. To add your own, write the classes in a custom_components/ directory and mount it in the container:

volumes:
- ./custom_components:/app/custom_components

This setup configures HERITRACE for OpenCitations Meta, with its own IRI generator, counter handler and save plugin:

environment:
COUNTER_HANDLER_CLASS: default_components.meta_filesystem_counter_handler.MetaFilesystemCounterHandler
COUNTER_HANDLER_OPTIONS: '{"info_dir": "/app/info_dir", "supplier_prefix": "09110", "base_iri": "https://w3id.org/oc/meta"}'
URI_GENERATOR_CLASS: default_components.meta_uri_generator.MetaURIGenerator
SAVE_PLUGIN_CLASS: default_components.meta_rdf_file_writer.MetaRDFFileWriter
SAVE_PLUGIN_OPTIONS: '{"rdf_dir": "/app/rdf", "base_iri": "https://w3id.org/oc/meta/", "dir_split_number": 10000, "items_per_file": 1000}'

Without URI_GENERATOR_CLASS, HERITRACE uses a built-in generator that mints IRIs of the form BASE_IRI/<uuid>. In this case BASE_IRI is required. Provenance snapshot counters are then stored in Redis, so the built-in default needs no code.

A custom IRI generator implements two methods:

  • generate_uri(entity_type: str | None = None) -> str: Generates a new URI for the given entity type
  • initialize_counters(sparql) -> None: Initializes any required state from existing data in the database

The counter handler keeps the numerical counters of counter-based IRI generators. Without it, such generators cannot guarantee unique IRIs across restarts.

A custom counter handler implements these methods:

  • read_counter(entity_name: str) -> int: Returns the current counter value for a given entity type, or 0 if the counter does not exist.
  • set_counter(new_value: int, entity_name: str): Sets the counter for an entity type to a specific value.
  • increment_counter(entity_name: str) -> int: Atomically increments the counter for an entity type by one and returns the new value.
  • close(): Closes any open connections (e.g., to a database).

A save plugin receives the working RDF graph after the dataset and provenance SPARQL updates and before HERITRACE commits its internal changes. It provides one method:

from typing import Protocol
from rdflib_ocdm.ocdm_graph import OCDMGraphCommons
class SavePlugin(Protocol):
def persist(self, graph_set: OCDMGraphCommons) -> None: ...

Without SAVE_PLUGIN_CLASS, HERITRACE runs no save plugin.

environment:
- ORCID_CLIENT_ID=your-client-id
- ORCID_CLIENT_SECRET=your-client-secret
  1. Create an ORCID Account: If you don’t already have one, create an ORCID account.

  2. Get Credentials:

  3. Configure Redirect URI:

    • In your ORCID application settings, add the redirect URI. The path is /auth/callback.
    • For local development: https://127.0.0.1:5001/auth/callback
    • For production: https://your-domain.com/auth/callback
  4. Add Credentials to docker-compose.yml: Update your environment variables with the credentials from ORCID.

    environment:
    - ORCID_CLIENT_ID=APP-XXXXXXXXXX # From ORCID registration
    - ORCID_CLIENT_SECRET=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  5. Add yourself as an administrator: Put your ORCID iD in ADMIN_ORCIDS. Then sign in and choose who else may sign in, under Access in the configuration editor.