Extending Orthanc with the Python plugin

The Orthanc Python plugin lets your team add REST routes, react to new instances and run scheduled work inside the server. This page covers what it makes possible, how to configure and secure it, and the AGPL obligations for your scripts.

On this page

When extending Orthanc with the Python plugin is the right move

The Python plugin is the right move when a hospital or imaging team needs Orthanc to do something its standard configuration cannot, and the logic is complex enough that a general-purpose language is easier to maintain than a pile of settings. With it, a team can add new REST routes to Orthanc, react to instances as they are stored, process DICOM content with pydicom, run scheduled tasks, and take over parts of C-STORE handling and storage. Typical needs include a custom endpoint that a local portal calls, a rule that tags or routes studies when they arrive, or a nightly cleanup job that the Orthanc configuration file cannot express. Before committing, confirm the exact plugin API for each of these capabilities in the Orthanc Book plugins documentation, since callback names and signatures are the details most likely to change between releases.

Python is usually the better choice than Lua when the workflow needs a rich library ecosystem, such as pydicom for parsing and modifying datasets, or when the team already maintains Python services and can reuse their testing and deployment habits. Lua scripts are lighter to start with, but a team that expects pixel-level work, complex data transformations or a growing body of code should weigh that maintainability difference early. Java is the stronger candidate when the organization standardizes on the JVM and wants compiled, strongly typed components with the same integration patterns it uses elsewhere. The decision should rest on who will own the code after go-live. Ask who will patch the scripts when Orthanc is upgraded, which language your on-call staff can read during an incident, and whether the plugin's runtime requirements fit your Orthanc packaging and container images.

Which capabilities teams build with the Python plugin

The Python plugin lets an Orthanc server run your own code inside the server process, reacting to events and exposing new endpoints. The six areas below cover the most common builds, and each carries a design risk that should shape the plan before any code is written.

New REST routes

Teams add custom endpoints so clinical applications, research tools or portals can call Orthanc with operations the built-in API does not offer. Because a route runs inside the server, it inherits none of the protections you may assume. Check who can call it, how input is validated, and whether it sits behind your authorization layer. The main risk is an unauthenticated or overly broad route exposed through a reverse proxy.

Orthanc plugins

Reacting to newly stored instances

A common pattern is running logic each time an instance is stored, such as tagging studies, notifying a worklist system or triggering a forward to another node. Work done in the callback delays storage for every incoming image, so heavy processing belongs in a queued job. The main risk is slow or failing callbacks that stall ingestion, so confirm throughput under your real modality load.

Pydicom-based processing

The pydicom library lets scripts read, modify and check DICOM datasets in Python, for example validating required tags or normalizing metadata before studies are shared. Pydicom work is CPU-bound and can be slow on large series or compressed transfer syntaxes. The main risk is changing data without an audit trail, so record what changed, which code version made the change, and how originals are preserved.

Scheduled tasks

Scheduled scripts handle recurring work such as purging expired studies, rebuilding indexes, exporting archives or reporting on storage growth. The plugin does not replace your job scheduler decisions, so decide whether tasks run inside Orthanc or as external jobs that call the REST API. The main risk is overlapping runs that compete for the same studies, so use locks and confirm behavior during restarts.

Custom storage and SCP handling

Some sites need DICOM handling that differs from the default, such as custom routing for specific modalities, alternate storage layouts or extra checks before accepting a transfer. Changes to how Orthanc accepts and stores data affect every sender on the network. The main risk is breaking existing modality connections, so test each change with the actual devices and keep a rollback path.

Integration with external services

Scripts often call identity, ticketing, research registry or reporting systems when an event occurs. Each outbound call adds a dependency, a credential and a failure mode that Orthanc must tolerate. Confirm where secrets are stored, how timeouts and retries are handled, and what happens to patient data sent to each service. The main risk is leaking credentials or identifiers through logs or unreviewed external endpoints.

Every request crosses two trust boundaries before it reaches storage

The diagram starts with a REST client or a modality sending C-STORE over the network into the Orthanc core. The core passes events and route calls to Python callbacks and routes, which can run pydicom processing on the dataset before the core writes files to the storage area and metadata to the database index. The subgraph borders mark where traffic enters the server and where the Python script runs inside it. Check each crossing: who may call a route, what the script may read or change, and whether a call to the external service carries patient data.

Requests and events move from the network through the Python plugin to storage.

Choosing the Python plugin, Lua or Java for each job

The Python plugin suits teams that already write Python and need DICOM processing beyond simple tag edits. Its main draw is the ecosystem: pydicom gives direct access to datasets, pixel arrays and transfer syntaxes, and the same language is common for data science, reporting and image analysis work. Scripts run inside the Orthanc process, so they can add REST routes, react to new instances and schedule tasks without a separate service. The trade-off is that a Python fault or a heavy computation can affect the server process, so the code needs careful error handling and resource limits.

  • Best fit: teams with Python skills who need pydicom, NumPy or other libraries in the processing path.
  • Routes and events: custom REST routes and callbacks for new or stored instances are part of the model.
  • Operational risk: a slow or crashing script runs alongside the core, so test load and failure behavior before production.
  • Deployment: the script and its Python dependencies must be packaged identically on every node, including containers and clusters.
  • Licensing: scripts that use Orthanc in a networked service may fall under AGPL obligations, so review them with counsel.

Before committing, confirm the Python version and plugin build your target Orthanc release supports, and test the dependency set in the same image you will deploy.

How to set up a Python plugin for Orthanc

This sequence takes a team from an Orthanc install with no scripting to a tested Python plugin that adds a REST route and reacts to new instances. Each step ends with a check so problems surface in a test environment before any patient data is involved.

  1. Confirm Orthanc version and plugin build compatibility

    The engineer responsible for the server records the Orthanc version in use and compares it with the Python plugin build offered for the same release line. Plugin builds are tied to specific Orthanc versions, so a mismatch is the most common reason a plugin fails to load. Confirm package names, version pairings and platform builds in the Orthanc download and plugins documentation before downloading anything. The step is done when the team has written down one Orthanc version and one matching plugin build for each target operating system or Docker image.

  2. Install the Python plugin in a test environment

    The engineer installs the matched Python plugin on a non-clinical Orthanc instance, such as a Docker container or a Linux package on a separate virtual machine, never on the production archive. Use the installation method from the download page for the chosen platform. Check that Orthanc starts cleanly and that its log shows the Python plugin being loaded. The step is done when the Orthanc Explorer or system endpoint reports the plugin as present and the log contains no load errors.

  3. Configure the plugin path and Python environment

    The engineer sets the plugin configuration keys that tell Orthanc where the Python plugin lives, where the script directory is, and which Python interpreter and packages the scripts can use. Keep the script folder under version control and give the service account read-only access to it. Pin any libraries such as pydicom to versions the team has tested. The step is done when a restart of Orthanc leaves the plugin loaded, and the log shows the configured script path being read without errors.

  4. Load a minimal script that registers one route

    The engineer writes a short script that registers a single REST route returning a fixed JSON response, then places it in the configured script folder and restarts Orthanc. The route should not read or write any DICOM data at this stage. The step is done when the script loads without a syntax or import error in the log, and the route appears in the list of Python-registered endpoints when the server is queried.

  5. Verify the route responds to requests

    The engineer calls the new route with an authenticated request from the same network segment the production clients would use, following the authentication settings in the security documentation. Remote access should stay restricted, and the team should confirm the route is not reachable from outside its allowed network. The step is done when the route returns the expected status code and body, and a request without valid credentials is refused.

  6. Add an instance event handler

    The engineer adds a handler that runs when Orthanc stores a new instance and writes only a log line containing the instance identifier and no patient data. This confirms that Orthanc calls the Python code on storage events. Keep the handler small, since slow code here delays the archive. The step is done when storing a test instance produces exactly one log entry from the handler, and the entry includes the expected identifier.

  7. Test the setup with sample DICOM data

    The engineer sends a set of public or synthetic DICOM files to the test instance through the REST API or a DICOM connection, then checks that the route and event handler both behave as expected for single files, multi-frame objects and repeated uploads. Record any errors and confirm that the handler does not block storage. Do not move to real data until these results are repeatable. The step is done when the test set produces the expected log entries and route results on every run, and the team has a written record of the versions tested.

Security risks to close before a script reaches production

A Python plugin runs inside the Orthanc process with the same reach as the server itself, so every custom route and file write widens the attack surface. The cards below cover the Orthanc settings that control who can reach the server, the routes that should stay off, and the handling of input, credentials and disk writes that your script introduces.

Review remote access and authentication

Orthanc accepts HTTP connections only from localhost by default. If RemoteAccessAllowed is enabled, confirm that AuthenticationEnabled is true and that every account is defined under RegisteredUsers. Check that custom routes registered by your script inherit this authentication rather than bypassing it. Record who holds those accounts and when they were last reviewed.

Orthanc security FAQ

Terminate TLS at a reverse proxy

Any exposure beyond your internal network should go through HTTPS and a reverse proxy in front of Orthanc, not direct port exposure. Confirm that the proxy enforces TLS, limits request size for upload routes, and forwards only the paths your script is meant to serve. Test that the Orthanc port itself is unreachable from outside the segment where the proxy sits.

Keep script execution and export routes off

The security FAQ warns that /tools/execute-script can let a malicious user run any system command, and that the export route can overwrite files. Both should stay disabled in production. Your Python routes should provide the specific behavior you need, so no general-purpose execution path is left for an attacker to reuse.

Validate input in custom routes

Every route your script exposes receives data from callers you may not control. Parse request bodies with explicit schemas, reject unexpected content types, and bound sizes before passing values into DICOM tags or file paths. Treat identifiers such as Study Instance UIDs as untrusted until they match the expected format. Include malformed and oversized requests in your test plan.

Store credentials for external services safely

Scripts that push to S3, a PACS or a messaging service need credentials. Keep them out of the script source and out of version control, load them from the environment or a secrets manager, and scope each key to the single bucket or endpoint the script uses. Ask who can read the configuration file on the server, and plan a rotation procedure before go-live.

Restrict what the script writes to disk

Limit the script's file system access to a dedicated working directory with the minimum permissions for the service account. Write temporary files there, not into the Orthanc storage area or system paths, and clean them up after each job. Check that a file name derived from request data cannot escape that directory through path traversal.

Add per-request access control when needed

When different users need different routes or studies, the advanced authorization plugin forwards each REST request's token to an external web service, which allows or denies access and returns HTTP 403 when denied. The orthanc-auth-service reference project uses Keycloak-issued tokens with Orthanc Explorer 2. Decide whether this layer is needed before your script's routes are exposed to more than one team.

Authorization plugin page

What AGPL means for scripts you write for Orthanc

The licensing picture for Orthanc is split by component, so the first question is which piece your script touches. The Orthanc core is licensed under the GNU GPLv3 or later, while scalability and cloud plugins, such as the PostgreSQL plugin and the web viewer plugins, are licensed under the GNU AGPLv3 or later. Python scripts that run through the Python plugin sit on top of this stack, so the license of your code depends on how it is written, how it is linked to Orthanc components, and whether you distribute it. The Orthanc Book licensing FAQ is the place to start before you assume anything about your own scripts.

The difference that matters most for in-house scripts is the AGPL network clause. A standard GPL license is typically triggered when you distribute software. The AGPL also attaches obligations when users interact with the modified program over a network, which can matter if a script adds REST routes that clinicians, researchers or partner sites call. Confirm with counsel whether a route your team exposes, a web page your script serves, or a modified plugin you run for an external group counts as offering the program to users over a network, and what source you would then need to make available. Keep an inventory of which scripts are internal, which are shared, and which are served through HTTP.

Copyright ownership also differs by component, which affects who can grant you terms. Orthanc copyright is shared among several holders, including the University Hospital of Liege, Osimis S.A. (now defunct), Orthanc Team SRL and UCLouvain, and the Orthanc Book notes that UCLouvain contributions since September 1, 2021 cannot be dual licensed. This is not legal advice. Ask your legal or compliance counsel to confirm the obligations for your specific code, your deployment model and your distribution plans, and record that review with the script so it can be revisited when Orthanc or the plugins are upgraded.

Limits to confirm in your own environment

The Python plugin ties your scripts to a specific Orthanc release, a specific Python build and a specific set of libraries. Each card below is a point where a script that works in a test instance can fail in production, so confirm each one against your own environment before you write code that depends on it.

Orthanc version in use

Confirm which Orthanc core release your servers run before you pin any script behavior to it. The latest release supplied is 1.13.0, released on 2026-08-15, which rewrote storage-area access and DICOM parsing and transcoding. The 1.12.x line, including 1.12.11 and 1.12.10, is the other line to consider if you cannot move yet. Check the NEWS file for the exact release notes that touch the callbacks and REST routes your script uses.

Orthanc NEWS file

Python plugin build for your platform

Confirm that the Python plugin is available as a build for your operating system, container image and architecture, and that it loads with the Orthanc version you run. Packaging differs across Windows, macOS, Linux packages and Docker images, so a plugin that loads in a development container may not load on a hospital Linux host. Ask for the exact plugin build and load test it on the same image that will run in production.

Orthanc downloads

pydicom and library versions

Pin the pydicom version and every other Python library your scripts import, and record the interpreter version the plugin uses. Changes in DICOM parsing, character set handling or transfer syntax support can alter the tags your code reads or writes. Test scripts against the pinned set after any change, and keep the lock file with the deployment so a rebuilt container does not pull newer packages silently.

Concurrency and blocking in callbacks

Measure how long each callback, such as an instance-received or stable-study handler, blocks Orthanc while it runs. A slow pydicom operation or a network call inside a callback can delay ingestion, and bursts of C-STORE traffic can queue behind it. Confirm the thread model with a load test that mirrors your modality volume, and move long work into a queued job or an external worker so the callback returns quickly.

Behavior on large datasets

The built-in SQLite index is meant for smaller archives. The Orthanc docs say it should be replaced by an enterprise database engine once several hundred thousand DICOM instances are stored, and they recommend the PostgreSQL plugin for large datasets. Test your script's REST calls and scheduled tasks against a dataset of realistic size, not a sample of a few hundred studies, and confirm that the database plugin you plan to use supports the routes your code relies on.

Instances before migration
Several hundred thousand
Scalability FAQ

Compatibility after Orthanc upgrades

Retest every script after each Orthanc upgrade, including minor releases. Check that the Python plugin version still matches the core, that REST routes and callback signatures used by your code have not changed, and that scheduled tasks still run. Keep a staging instance with the same plugin and library versions, and ask whether your upgrade plan includes a rollback path for the database and the scripts together.

Questions teams ask before extending Orthanc with Python

What does it cost to extend Orthanc with a Python plugin?

The cost is mostly labor, and it depends on how many routes and callbacks you need, how much DICOM test data you can use, and how much security review the work requires. Your internal engineers, or a partner you pay, carry the development time. Orthanc itself has no paid edition, so the software license adds nothing to the bill. Recurring costs come from keeping the scripts working after each Orthanc upgrade, which means regression testing against your own sample studies. Ask any quote to itemize design, development, testing, security review, documentation and post-upgrade retesting separately, and to state which items are one-time and which recur. DeployOpen quotes follow from a written scope, and Orthanc Team SRL quotes its services on request.

How long does a Python plugin extension take to build?

Duration depends on the scope of the routes and event handlers, the number of DICOM variants your data contains, the integrations the plugin must call, and how long your review and approval steps take. A single REST route that reads metadata is a much smaller job than a custom storage handler that must behave correctly across modalities and transfer syntaxes. Ask any vendor or partner for a schedule tied to a written scope, with named milestones for test data, staging, security review and production cutover. Ask your own team to estimate the same items, because the testing and review phases often take longer than the coding.

What must our team provide before a Python extension project starts?

Four things reduce risk and delay. First, representative DICOM sample data from each modality and site that will send studies, including the transfer syntaxes you actually receive. Second, a test environment that matches production in Orthanc version, database back end and network path, so results carry over. Third, a named owner who can make decisions about behavior, acceptance and priorities. Fourth, access to the target infrastructure, including the Orthanc hosts, the database, identity systems and any downstream services the plugin calls. Request a written list of these inputs in the scope document, and confirm access and data-handling approvals early, especially when patient images are involved.

Can our internal team build and maintain a Python plugin without a partner?

Yes, if your team has Python experience, familiarity with DICOM attributes and the Orthanc plugin SDK, and capacity to test against real studies. Many teams start in-house and bring in a partner only for a specific gap, such as a security review or an unfamiliar DICOM edge case. The harder long-term question is whether someone will own the plugin after go-live. Each Orthanc upgrade can change behavior your scripts depend on, so plan a retest cycle and a documented handover. Orthanc Team SRL sells pre-paid dedicated support hours valid for 12 months, quoted on request, which can cover targeted questions without a full project.

Does an AGPL license affect the Python scripts we write for Orthanc?

Start by separating the components. The Orthanc core is licensed GPLv3 or later, while several scalability and cloud plugins, such as the PostgreSQL and web viewer plugins, are AGPLv3 or later. Whether your own scripts carry obligations depends on how they link to, extend or distribute those components, and on whether you offer the modified software to users over a network. Your legal counsel should review the exact plugins and deployment model you use. Read the licensing FAQ in the Orthanc Book before the decision, and record the conclusion in your open-source inventory. This is a legal question, so do not treat engineering guidance as a license opinion.

What breaks most often in Python plugins for Orthanc?

The most common failures come from assumptions about input. Scripts fail when they meet unexpected transfer syntaxes, missing or private tags, inconsistent patient identifiers, or very large studies that exhaust memory. Exposed REST routes can also create security exposure if authentication is weak. Orthanc's security guidance says that remote access should be paired with authentication and users defined in RegisteredUsers, and that HTTPS and a reverse proxy are recommended for Internet exposure. It also warns that the /tools/execute-script route and the export route can be dangerous and should stay disabled. Verify each route with negative tests, malformed files and an authorization check before release.

When should we bring in Orthanc Team SRL or DeployOpen?

Bring in an outside partner when the work carries risk that your team cannot cover alone, such as a security review of a plugin that handles patient images, a custom storage handler that must be proven correct, or a deadline that your staff cannot meet. Orthanc Team SRL sells deployment, configuration and development services, including pre-paid dedicated support hours. DeployOpen implements, hardens, documents and supports self-hosted open-source platforms in your own infrastructure, and most engagements are fixed-scope with written deliverables. Ask either provider for a written scope, the test evidence they will hand over, and how they will support the plugin after an Orthanc upgrade.

Where to confirm plugin details and licensing

Before you build anything on the Python plugin, confirm the exact API and version behavior in the official Orthanc Book plugins page, which lists the official plugins and their scope. Treat that page as the starting point for what is supported, then check the plugin's own documentation for the functions your scripts call, because the names and behavior of Python callbacks, REST route registration and storage hooks can differ between core releases. Record the Orthanc core version and the Python plugin build you tested against, so a later upgrade can be reviewed against the same baseline.

The licensing FAQ settles whether your scripts fall under the same terms as the core or the plugins you load with them. The core is GPLv3 or later, and several plugins are AGPLv3 or later, so your legal or compliance team should read that page with the list of plugins in your deployment in hand. Confirm with counsel how your own scripts are licensed and whether any distribution to other organizations triggers source obligations. The Orthanc NEWS file lists release changes, so check it for every version you plan to run, since changes to plugin interfaces are recorded there.

The security FAQ and scalability FAQ answer the questions that shape your design. The security FAQ explains how REST access, authentication and dangerous routes must be configured before any script is exposed to users, and the scalability FAQ explains when a single SQLite index should be replaced and how multiple instances share one database. Read both before you decide whether your Python routes run on a single server or across a cluster, and check that any new endpoint you add respects the authorization setup described in the security FAQ.

How DeployOpen scopes and delivers a Python extension for Orthanc

A Python extension touches routes, events and stored patient data, so the work is shaped by a written scope before any code is written. The cards below follow the path from scope to handover and the ongoing care that follows, and each step is agreed with the client before the next one starts.

Written scope of routes and callbacks

Scope starts with an inventory of every REST route, event callback, scheduled task and DICOM handler the extension needs, along with the Orthanc version it must run on. Each item is written down with its inputs, outputs and the systems it calls. Ask for the scope list to name every callback so that unexpected hooks do not appear later. Most engagements are fixed-scope, so a quote follows from this written document.

Orthanc plugins docs

Build and test inside your infrastructure

The extension is built and tested in environments the client controls, using test Orthanc instances that mirror production settings. pydicom processing is checked against sample studies that the client approves for use. Confirm where test data is stored and who can access it, since copies of patient images in build environments are a common compliance gap.

Security testing of endpoints

Every new REST route is tested for authentication, authorization and input handling before handover. The /tools/execute-script route and export routes are checked to confirm they remain disabled, as the Orthanc security guidance recommends. Confirm that each route requires an authenticated user and that RemoteAccessAllowed settings match the agreed design.

Orthanc security FAQ

Documentation and handover

Delivery includes documentation of the routes, configuration keys, callback behavior, deployment steps and rollback method. Operators receive a walkthrough so that the team can run, debug and restart the plugin without the original builders. Ask for the handover to cover logs, failure modes and the list of stored credentials, with each credential's owner named.

Licensing review of scripts

Before delivery, the team confirms how the extension's code relates to the Orthanc licensing terms, since the core is GPLv3 or later and some plugins are AGPLv3 or later. Scripts that run inside a licensed server need a deliberate license choice and a record of it. Ask your legal or compliance team to review the chosen license before code is distributed to other organizations.

Orthanc licensing FAQ

Retainers for upgrades and testing

Orthanc releases change core behavior, so an extension may need updates after each upgrade. Retainers cover upgrade testing of the extension, periodic security retesting and fixes between releases. Confirm in the retainer terms how long the team commits to each supported Orthanc line and how upgrade tests are scheduled against the release cycle.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.