# TurboBulk (/docs/turbobulk)



TurboBulk is a high-performance bulk data API for NetBox that loads, updates, deletes, and exports tens of thousands of objects per second - orders of magnitude faster than the REST API. It uses PostgreSQL COPY, staging tables, and Apache Parquet to achieve throughput of 5,000–25,000 rows/sec across all NetBox object types.

**Availability:** Premium tier on [NetBox Cloud](https://netboxlabs.com/netbox-cloud/) and NetBox Enterprise. On NetBox Enterprise, the plugin is built in from 2.2 onward; see [TurboBulk on NetBox Enterprise](https://netboxlabs.com/docs/enterprise/nbe-turbobulk/) for how to enable it and which version each release bundles.

**Client library, detailed docs, and examples:** [netboxlabs/netbox-turbobulk-public](https://github.com/netboxlabs/netbox-turbobulk-public)

***

## When to use TurboBulk [#when-to-use-turbobulk]

| Use case                   | Example                                                     |
| -------------------------- | ----------------------------------------------------------- |
| Initial data population    | Migrate an existing DCIM/IPAM into NetBox                   |
| Ongoing syncs              | Nightly import of 500K IP addresses from an external source |
| Bulk exports for analytics | Export all devices + interfaces to a data warehouse         |
| Large-scale changes        | Re-assign 100K interfaces to a new VLAN group               |
| Branch-based workflows     | Load proposed changes into a NetBox branch, review, merge   |

### When NOT to use TurboBulk [#when-not-to-use-turbobulk]

* **\< 1,000 objects** - the REST API is fine at this scale.
* **Interactive single-object edits** - use the NetBox UI or REST API.
* **Workflows that depend on synchronous custom validators** - TurboBulk does not execute Django model validators (DB constraints are still enforced).
* **Workflows that depend on per-object webhooks firing in real time** - events are dispatched asynchronously after the entire operation completes.

### TurboBulk vs. Replica Cache [#turbobulk-vs-replica-cache]

TurboBulk is for bulk reads and writes with real-time consistency against the primary database. [Replica Cache](https://netboxlabs.com/docs/cloud/features/replica-cache/) is a read-only API backed by a replica with zero primary-DB load and outage resilience. They are complementary - use Replica Cache for high-frequency reads and TurboBulk for bulk writes and exports.

***

## Capabilities [#capabilities]

| Capability         | Description                                                                                                                                                                               |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Bulk insert        | Insert new rows from JSONL or Parquet files                                                                                                                                               |
| Bulk upsert        | Insert or update on conflict (configurable conflict fields or named constraints)                                                                                                          |
| Bulk delete        | Delete rows by primary key or custom key fields, with cascading FK nullification                                                                                                          |
| Bulk export        | Export full tables or filtered subsets to JSONL (gzipped) or Parquet                                                                                                                      |
| Export caching     | Server-side cache with TTL - repeated exports return instantly via cache key; clients that echo back `client_cache_key` + `client_cache_version` get HTTP 304 while their copy is current |
| Dry-run validation | Validate data without committing; returns errors and rolls back                                                                                                                           |
| Validation modes   | `none` (skip), `auto` (SQL pre-validation for IP/prefix), `full` (Django `full_clean()` per row)                                                                                          |
| Branching          | Operate within a NetBox branch (requires netbox-branching plugin)                                                                                                                         |
| Changelogs         | Generate `ObjectChange` records for audit trail (opt-in per operation)                                                                                                                    |
| Event dispatch     | Fire webhooks and event rules after operation completes (async)                                                                                                                           |
| Save hooks         | Replicate model `save()` side-effects as bulk SQL (computed fields, denormalization)                                                                                                      |

All write operations are fully atomic - they succeed completely or roll back with no partial state.

***

## Getting started [#getting-started]

### Prerequisites [#prerequisites]

* NetBox Cloud or NetBox Enterprise on a Premium-tier license, with TurboBulk enabled
* A NetBox API token with appropriate object permissions
* Python 3.10+

### Install the client [#install-the-client]

```bash
pip install turbobulk-client
```

### Quick example [#quick-example]

```python
import os
from turbobulk import TurboBulkClient

client = TurboBulkClient(
    url=os.environ["NETBOX_URL"],
    token=os.environ["NETBOX_TOKEN"],
)

# Bulk insert sites
data = [
    {"name": "Site-A", "slug": "site-a", "status": "active"},
    {"name": "Site-B", "slug": "site-b", "status": "active"},
]
result = client.load("dcim.site", data, mode="insert")
print(f"Inserted {result['rows_inserted']} sites")

# Bulk export all sites
export = client.export("dcim.site")
print(f"Exported {export['rows_exported']} sites")
```

For more examples, see the [example scripts](https://github.com/netboxlabs/netbox-turbobulk-public/tree/main/examples) in the public repo.

***

## Data formats [#data-formats]

TurboBulk supports two wire formats:

| Format  | Extension             | Best for                             | Notes                                                     |
| ------- | --------------------- | ------------------------------------ | --------------------------------------------------------- |
| JSONL   | `.jsonl`, `.jsonl.gz` | Simplicity, small-to-medium datasets | One JSON object per line. Gzip supported. Default format. |
| Parquet | `.parquet`            | Maximum throughput, 100K+ rows       | Columnar, compressed, strongly typed. Requires PyArrow.   |

Format is auto-detected from file content, `Content-Type` header, or filename extension. When in doubt, start with JSONL - switch to Parquet when throughput matters.

***

## Important caveats [#important-caveats]

### FK columns must use the `_id` suffix [#fk-columns-must-use-the-_id-suffix]

This is the most common source of errors. Foreign key fields must reference the database column name (with `_id` suffix), not the Django relation name:

```json
{"name": "switch-01", "site_id": 1, "role_id": 3, "device_type_id": 5}
```

Not: `{"name": "switch-01", "site": 1, "role": 3, "device_type": 5}`

Use `GET /api/plugins/turbobulk/models/{model}/` to discover the exact field names and types for any model.

### Exported JSON types are not always the column types [#exported-json-types-are-not-always-the-column-types]

In a JSONL export, several field types arrive as a different JSON type than
`db_type` or `arrow_type` would suggest. Each field in the schema response carries a
`jsonl_type` giving the type actually written, so clients do not have to infer it:

| Field type                                  | `arrow_type`                      | In JSONL         | Why                                                    |
| ------------------------------------------- | --------------------------------- | ---------------- | ------------------------------------------------------ |
| `DecimalField`                              | `decimal128(p,s)`                 | `"42.50"` string | Serialised via `json.dumps(default=str)`               |
| `JSONField`                                 | `string`                          | JSON **string**  | Encoded before writing; an empty object becomes `null` |
| `ArrayField`                                | `string`                          | JSON array       | Lists are written through unchanged                    |
| `DateTimeField` / `DateField` / `TimeField` | `timestamp` / `date32` / `time64` | ISO string       | `isoformat()`                                          |
| `ForeignKey`                                | `int64`                           | integer          | The related primary key, never a nested object         |

A `custom_field_data` value therefore needs parsing twice - once as the JSONL line,
then again as the string it holds.

Each field also carries:

* `jsonl_nullable` - whether the export can write `null`, which is wider than
  `nullable`. An empty JSON object is written as `null` even where the column is
  `NOT NULL`, so `custom_field_data` is `nullable: false` and `jsonl_nullable: true`.
* `array_item_type` - the JSON type of the items when `jsonl_type` is `array`.
* `choice_labels` - value to human label for choice fields. The export writes the
  bare value (`active`), so this is the only source for the label a UI would show
  (`Active`).

`_tags` is not a model field: it is appended when `include_tags` is requested (the
default) and holds an array of tag slugs. The schema lists it under
`export_only_columns`, described with the same keys a field carries, so `fields` plus
`export_only_columns` can be concatenated and treated as one typed list describing an
export row exactly.

`jsonl_format_version` gives the version of the value encoding above. It is bumped
when the JSON type or encoding of any column changes, so a consumer can pin the
contract rather than discovering a change by misreading values. Adding or removing a
column does not bump it - columns are already discoverable per model.

### Custom validators are not executed [#custom-validators-are-not-executed]

TurboBulk bypasses the Django ORM for writes. Database constraints (NOT NULL, UNIQUE, FK) are enforced by PostgreSQL. Built-in validation is available via `validation_mode` (`auto` or `full`), but custom model validators and `clean()` methods are not called.

### Write operations are disabled by default [#write-operations-are-disabled-by-default]

Write operations are disabled by default for safety. [Contact NetBox Labs](https://netboxlabs.com/contact-us/) to enable writes and tune the TurboBulk configuration for safety and performance in your environment. We recommend starting with export-only operations to validate your workflow before enabling writes.

### Events are dispatched asynchronously [#events-are-dispatched-asynchronously]

Webhooks and event rules fire after the entire operation completes, not per-object during the operation. Custom scripts are not triggered. Set `dispatch_events: true` in your request to enable event dispatch.

For branch-scoped operations, event dispatch is skipped: events for branch changes fire when the branch is merged into main.

***

## Limits [#limits]

| Limit               | Value  |
| ------------------- | ------ |
| Maximum upload size | 1 GB   |
| Job timeout         | 1 hour |
| NetBox version      | 4.5+   |

***

## API endpoints [#api-endpoints]

All endpoints are under `/api/plugins/turbobulk/`. Authentication is via NetBox API token, or - where platform authorization is enabled - a NetBox Identity Token (NIT), presented as `Bearer` on NetBox Cloud and as `JWT` on NetBox Enterprise.

| Method | Endpoint                          | Description                                              |
| ------ | --------------------------------- | -------------------------------------------------------- |
| `GET`  | `/models/`                        | List all available models and their capabilities         |
| `GET`  | `/models/{app_label.model_name}/` | Get full schema for a model (fields, types, constraints) |
| `POST` | `/load/`                          | Bulk insert or upsert from JSONL/Parquet                 |
| `POST` | `/delete/`                        | Bulk delete by primary key or custom key fields          |
| `POST` | `/export/`                        | Bulk export to JSONL or Parquet (async job)              |
| `GET`  | `/jobs/{job_id}/`                 | Check job status and results                             |
| `GET`  | `/jobs/{job_id}/download/`        | Download export result file                              |
| `GET`  | `/cache/{cache_key}/download/`    | Download cached export by cache key                      |

### Export client caching (HTTP 304) [#export-client-caching-http-304]

`cache_key` names the export *request* (a hash of model, filters, fields, options, format and the caller's authorization scope). It is the same across every rebuild of the cache entry, so it cannot say whether a client's copy is still current. Each build of the entry also has a `cache_version`, returned in the cached `200` response. A completed export job's `data` carries `cache_stored`, and when it is `true`, the `cache_key` and `cache_version` of the file it produced. `cache_stored` is `false` when the result could not be cached. A build's validity starts when its export began reading rows, so a change made while the export runs invalidates that build.

To skip a download, send both values from the copy you hold as `client_cache_key` and `client_cache_version`. The server returns `304 Not Modified` only when both match the current, still-valid entry. Any other request that hits the cache, including one with `client_cache_key` but no `client_cache_version`, gets the normal cached `200` with a `download_url`. Clients written before `cache_version` existed therefore re-download instead of getting a `304`: slower, but never stale.

For full request/response schemas and parameter details, see the [API Reference](/turbobulk/api-reference/).

***

## Resources [#resources]

| I want to...                                 | Link                                                                                 |
| -------------------------------------------- | ------------------------------------------------------------------------------------ |
| Get started with the client library          | [Quickstart](/turbobulk/quickstart/)                                                 |
| See working code examples                    | [Examples](https://github.com/netboxlabs/netbox-turbobulk-public/tree/main/examples) |
| Read full API documentation                  | [API Reference](/turbobulk/api-reference/)                                           |
| Understand validation, hooks, and changelogs | [User Guide](/turbobulk/user-guide/)                                                 |
| Use TurboBulk with NetBox Branching          | [Branching Guide](/turbobulk/branching/)                                             |
| Troubleshoot errors                          | [Troubleshooting](/turbobulk/troubleshooting/)                                       |
| Report an issue or request a feature         | [GitHub Issues](https://github.com/netboxlabs/netbox-turbobulk-public/issues)        |
| Get support                                  | [Contact NetBox Labs](https://netboxlabs.com/contact-us/)                            |
