Configuration

tiny_pacs is configured through YAML or JSON files, command-line options and an interactive wizard. This tutorial covers the configuration file format and the tools to create one.

Configuration files

A configuration file has three optional top-level sections: ae, log and components. Anything that is not provided falls back to the built-in defaults.

Configuration is described with pydantic models and validated when it is loaded, so unknown keys, wrong types or out-of-range values are rejected up front with a pydantic.ValidationError instead of surfacing as obscure errors at runtime:

The ae section

Application entity settings:

  • ae_title — a list of AE titles the server answers to (default: ['TINY_PACS'])

  • port — the SCP TCP port (default: 11112)

  • max_pdu_length — maximum PDU length in bytes (default: 65536)

  • dump_ds — dump datasets and PDUs to the log (default: true)

  • supported_ts — a list of supported transfer syntax UIDs (default: the common uncompressed, JPEG, JPEG-LS, JPEG 2000, MPEG and RLE syntaxes)

  • tls — when present, all incoming connections are wrapped in TLS. A mapping with the certificate and, if the key is stored separately, the key entry pointing to PEM files, and an optional ca entry. When ca is given, client certificates are verified against it:

ae:
  tls:
    certificate: /etc/tiny_pacs/server.pem
    key: /etc/tiny_pacs/server.key
    ca: /etc/tiny_pacs/ca.pem

The log section

A standard Python logging.config.dictConfig schema. The default configuration installs a console handler with DEBUG level:

log:
  version: 1
  formatters:
    simple:
      format: '%(asctime)s - %(levelname)-8s - %(name)-15s - %(message)s'
  handlers:
    console:
      class: logging.StreamHandler
      level: DEBUG
      formatter: simple
      stream: ext://sys.stdout
  root:
    level: DEBUG
    handlers: [console]

The components section

A mapping of component name to its configuration. The built-in components are described in Introduction; every component accepts an on flag and is skipped unless it is set to true. When no components are configured at all, the default set is used: Database, Devices, PACS and InMemoryStorage.

Note

A component entry provided in a configuration source replaces any previous entry for that component wholesale — omitted fields fall back to the model defaults.

A complete example

ae:
  ae_title: [TINY_PACS]
  port: 11112
  max_pdu_length: 65536
  dump_ds: false
log:
  version: 1
  formatters:
    simple:
      format: '%(asctime)s - %(levelname)-8s - %(name)-15s - %(message)s'
  handlers:
    console:
      class: logging.StreamHandler
      level: INFO
      formatter: simple
      stream: ext://sys.stdout
  root:
    level: INFO
    handlers: [console]
components:
  Database:
    on: true
    driver: sqlite            # or postgres
    db_name: pacs.db          # SQLite database name, default 'pacs.db'
    mode: rwc                 # 'rwc' persists to the db_name file; the
                              # default 'memory' keeps data in RAM only
  Devices:
    on: true
    auto_add: true            # register calling AE titles automatically
    default_port: 11113       # port used for auto-added devices
    devices:
      WORKSTATION:
        aet: WORKSTATION
        address: 192.168.1.10
        port: 11113
        # Optional DICOM user identity for outgoing connections to this
        # device (used for C-MOVE sub-operations and Storage Commitment):
        # username: dicom_user
        # password: secret
  PACS:
    on: true
  FileStorage:
    on: true
    storage_dir: /var/lib/tiny_pacs/storage

The PostgreSQL driver takes connection parameters instead:

components:
  Database:
    on: true
    driver: postgres
    db_name: tiny_pacs_db
    host: localhost
    port: 5432
    user: postgres
    password: postgres
    max_conn: 20

Generating configuration files

Instead of writing the file by hand, generate a YAML configuration filled with the default values — either print it to stdout or write it to a file:

tiny-pacs config
tiny-pacs config -o config.yaml

Files written by tiny-pacs config are created with restrictive permissions (0600), because configurations may contain credentials such as the PostgreSQL password.

Interactive configuration

Both commands can run in interactive mode: the wizard asks for every configuration value. With config the result is written to --output (or printed to stdout), with run it is merged into the server configuration and the wizard offers to save it to a file before starting the server:

tiny-pacs config -i -o config.yaml
tiny-pacs run -i

Next steps

With a configuration file in hand, continue to Running tiny_pacs to start the server and send your first DICOM association.