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.
Configuration method
Section titled “Configuration method”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-secretCore application settings
Section titled “Core application settings”| Environment Variable | Type | Description | Required | Default |
|---|---|---|---|---|
SECRET_KEY | String | Flask secret key that signs the session cookies | Yes | None |
FLASK_ENV | String | demo signs every visitor in as the demo user http://example.org/demo/demo_user, without ORCID. development and production require ORCID | No | development |
FRONTEND_ORIGINS | String | Origins 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 from | No | None |
Configuration folder
Section titled “Configuration folder”| Environment Variable | Type | Description | Required |
|---|---|---|---|
CONFIG_DIR | Path | Folder that holds the configuration. A relative path starts from the HERITRACE folder | Yes |
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/configWhen the folder has no valid configuration, HERITRACE starts in setup mode and waits for an administrator to provide one. See Setup mode.
Administrators
Section titled “Administrators”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-3700Administrators 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.
Gunicorn configuration
Section titled “Gunicorn configuration”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 Variable | Type | Description | Default |
|---|---|---|---|
GUNICORN_WORKERS | Integer | Number of Gunicorn worker processes | (2 * CPU cores) + 1 |
GUNICORN_TIMEOUT | Integer | Maximum seconds a worker can spend handling a single request before being restarted | 120 |
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.
Redis configuration
Section titled “Redis configuration”HERITRACE uses Redis for counter management and caching. You can use either an internal Redis instance (default) or connect to an external Redis server.
Internal Redis (default)
Section titled “Internal Redis (default)”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:
docker compose exec web redis-cli DEL heritrace:counters_initializedExternal Redis
Section titled “External Redis”To use an external Redis instance, set the REDIS_URL environment variable:
environment: - REDIS_URL=redis://heritrace-redis:6379/0HERITRACE skips counter initialization when it uses an external Redis instance, so make sure the counters are already there.
| Environment Variable | Type | Description | Required | Default |
|---|---|---|---|---|
REDIS_URL | String | Connection URL for external Redis server | No | redis://localhost:6379/0 (internal) |
Database configuration
Section titled “Database configuration”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 Variable | Options | Description |
|---|---|---|
DATASET_DB_TRIPLESTORE | virtuoso, blazegraph, qlever | Type of the dataset database |
PROVENANCE_DB_TRIPLESTORE | virtuoso, blazegraph, qlever | Type of the provenance database |
DATASET_DB_URL | URL | SPARQL endpoint of the dataset database |
PROVENANCE_DB_URL | URL | SPARQL endpoint of the provenance database |
DATASET_IS_QUADSTORE | true/false | Enable named graph support |
PROVENANCE_IS_QUADSTORE | true/false | Enable provenance named graphs |
DATASET_DB_TEXT_INDEX_ENABLED | true/false | Search for existing entities with the full-text index of the dataset database |
Database options
Section titled “Database options”environment: - DATASET_DB_TRIPLESTORE=virtuoso - PROVENANCE_DB_TRIPLESTORE=virtuosoPros:
- 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
environment: - DATASET_DB_TRIPLESTORE=blazegraph - PROVENANCE_DB_TRIPLESTORE=blazegraphPros:
- Simple to configure
- Open source and SPARQL 1.1 compliant
- Full-text indexing and named graph support
Cons:
- No longer actively maintained
- Performance degrades and may stop accepting triples with large datasets
- Poor documentation
Components
Section titled “Components”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 Variable | Description | Default |
|---|---|---|
URI_GENERATOR_CLASS, URI_GENERATOR_OPTIONS | Creates the IRIs of new entities | The built-in generator |
COUNTER_HANDLER_CLASS, COUNTER_HANDLER_OPTIONS | Stores the counters of counter-based IRI generators | A counter handler in Redis |
SAVE_PLUGIN_CLASS, SAVE_PLUGIN_OPTIONS | Receives each change after HERITRACE writes it to the databases | None |
BASE_IRI | Base IRI of the built-in IRI generator | None |
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_componentsThis 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}'Built-in IRI generator
Section titled “Built-in IRI generator”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.
IRI generator
Section titled “IRI generator”A custom IRI generator implements two methods:
generate_uri(entity_type: str | None = None) -> str: Generates a new URI for the given entity typeinitialize_counters(sparql) -> None: Initializes any required state from existing data in the database
Counter handler
Section titled “Counter handler”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, or0if 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).
Save plugin
Section titled “Save plugin”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.
ORCID integration
Section titled “ORCID integration”environment: - ORCID_CLIENT_ID=your-client-id - ORCID_CLIENT_SECRET=your-client-secretSetting up ORCID
Section titled “Setting up ORCID”-
Create an ORCID Account: If you don’t already have one, create an ORCID account.
-
Get Credentials:
- Go to ORCID Developer Tools.
- Create a new application and note your Client ID and Client Secret.
-
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
- In your ORCID application settings, add the redirect URI. The path is
-
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 -
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.
