Domain-agnostic Python framework for digital twin architectures
Project description
DT-Forge
A domain-agnostic Python framework for building digital twins of any physical asset.
DT-Forge implements a six-layer Digital Twin architecture — Data, Simulation & Model, Services, Reactive, Intelligent, and Autonomous — along with a Connector subsystem for inter-twin communication and four collection-twin patterns.
Architecture
┌─────────────────────────────────────────────┐
│ AUTONOMOUS LAYER │
│ OODA loop · Goal planner · RL policies │
├─────────────────────────────────────────────┤
│ INTELLIGENT LAYER (MAS) │
│ LangChain agents · Neo4j knowledge graph │
├─────────────────────────────────────────────┤
│ REACTIVE LAYER │
│ Threshold FSM · PID controllers │
├─────────────────────────────────────────────┤
│ SERVICES LAYER │
│ Eclipse Ditto sync · FastAPI REST/SSE │
├─────────────────────────────────────────────┤
│ SIMULATION & MODEL LAYER │
│ ODE · ONNX surrogate · SimPy · Prophet │
├─────────────────────────────────────────────┤
│ DATA LAYER │
│ InfluxDB · MongoDB · Redis · MinIO │
├─────────────────────────────────────────────┤
│ DT NETWORK LAYER │
│ MQTT ingestion · Pydantic validation │
└─────────────────────────────────────────────┘
Collection patterns
| Pattern | Use case |
|---|---|
AggregateDT |
Fleet of identical assets — fused state, shared control |
CollectionDT |
Batch monitoring, outlier detection, statistical comparison |
CompositeDT |
Hierarchical systems with boundary condition exchange |
NetworkDT |
Graph-topology systems, cascade risk, bottleneck detection |
Quick start
1. Install
pip install -e .
2. Configure
cp .env.example .env # then edit .env with your asset ID, LLM key, etc.
3. Start infrastructure
Generate a docker-compose.yml for the layers you need and bring them up
in a single step:
# Minimal (data + MQTT + Ditto):
dtforge infra up --layers data,network,services
# Full stack (adds Neo4j for the intelligent layer):
dtforge infra up --layers data,network,services,intelligent
dtforge infra up writes the compose file and runs docker compose up -d.
Pass --generate-only if you only want the file written (e.g. to commit it):
dtforge infra up --layers data,network,services --generate-only
docker compose up -d
Wait for all services to be ready:
dtforge infra check --layers data,network,services,intelligent
Every service shows ✓ when the twin can connect to it.
What gets started:
| Service | Port | Purpose |
|---|---|---|
| Mosquitto | 1883 | MQTT message broker |
| InfluxDB | 8086 | Time-series sensor readings |
| MongoDB | 27017 | Events, audit log |
| Redis | 6379 | Session cache, FSM state |
| MinIO | 9000 | Trained models, file objects |
| Eclipse Ditto | 8080 | Canonical twin state |
| Neo4j | 7687 | Knowledge graph (intelligent layer) |
| Grafana | 3000 | Observability dashboard (optional) |
Pre-built implementations (e.g.
implementations/sdt/) ship with a ready-madedocker-compose.ymltuned for their specific configuration. Use that instead of generating one from scratch.
4. Scaffold a new twin
dtforge init --asset-type centrifugal_pump --name "Plant A Pump" --asset-id pump_001
This creates:
twin.py— twin class scaffold (editbuild_layers()to wire your logic).env— environment configuration
5. Run
python twin.py
Or via the CLI:
dtforge run twin
Configuration
All settings are driven by environment variables with the DT_ prefix.
Nested fields use double-underscore as a delimiter:
DT_ASSET_ID=pump_001
DT_MQTT__BROKER=192.168.1.10
DT_INFLUX__TOKEN=my-token
DT_LLM__PROVIDER=anthropic
DT_LLM__MODEL=claude-sonnet-4-6
DT_LLM__API_KEY=sk-ant-...
See .env.example for a full reference.
Extending the framework
| Extension point | Mechanism |
|---|---|
| New storage backend | Implement TimeSeriesStore / DocumentStore protocol |
| New physics model | Subclass ODEModel or implement TwinModel protocol |
| New ML surrogate | Implement TwinModel with ONNX/sklearn |
| Custom reactive rule | Implement Rule protocol |
| New agent | Implement TwinAgent protocol |
| New LLM provider | Swap build_llm() in intelligent/agent.py |
| Custom connector | Implement ConnectorProtocol |
| New collection pattern | Subclass AbstractCollectionTwin |
| Custom RL reward | Pass reward_fn to GenericTwinEnv |
Technology stack
| Concern | Technology |
|---|---|
| Messaging | Eclipse Mosquitto / paho-mqtt |
| Time-series | InfluxDB 2 |
| Documents | MongoDB |
| Cache / pub-sub | Redis |
| Object storage | MinIO |
| Twin state | Eclipse Ditto |
| Knowledge graph | Neo4j |
| Agents | LangChain + OpenAI / Anthropic / Ollama |
| RL | Stable-Baselines3 + Gymnasium |
| API | FastAPI + Uvicorn |
| Validation | Pydantic v2 |
| State machine | transitions |
| PID control | simple-pid |
| Physics solver | SciPy (solve_ivp) |
| Discrete event | SimPy |
| Forecasting | Prophet |
CLI reference
dtforge init # scaffold a new twin project
dtforge infra up # generate docker-compose.yml
dtforge infra check # check infrastructure readiness
dtforge run # run the twin
dtforge train # train an RL policy
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dt_forge-0.4.0.tar.gz.
File metadata
- Download URL: dt_forge-0.4.0.tar.gz
- Upload date:
- Size: 78.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c013a5b6862d65b2bb9948993260a1ad342ccc9838bd66d44c73b0bf3abdf8b
|
|
| MD5 |
49290369f4e54ebff7e8b4f2f0430fab
|
|
| BLAKE2b-256 |
038e10bc92547dbae639f999329fa844e7782942e74064f3cf15e15f3d27c5a5
|
File details
Details for the file dt_forge-0.4.0-py3-none-any.whl.
File metadata
- Download URL: dt_forge-0.4.0-py3-none-any.whl
- Upload date:
- Size: 109.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ab14b02e1f7901a38cea6636f7418cc5c1d26fa253e285fba1d4193c62f9c09
|
|
| MD5 |
f8f59f0d5f43dddd5413342a6520c8bf
|
|
| BLAKE2b-256 |
72861495b2b745310884076d3109e58dab085bba2ab9b09a43d9408fe55963bd
|