# UK BNG Register Scraper (`vagile_airliner/uk-bng-register-scraper`) Actor

Structured feed of the UK Biodiversity Net Gain (BNG) sites register: gain sites, habitat units, local planning authority allocations, and responsible bodies, pulled from the official Defra Biodiversity Net Gain data API behind the GOV.UK search UI.

- **URL**: https://apify.com/vagile\_airliner/uk-bng-register-scraper.md
- **Developed by:** [milan Pecka](https://apify.com/vagile_airliner) (community)
- **Categories:** Lead generation, Real estate
- **Stats:** 2 total users, 1 monthly users, 15.4% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-usage

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## UK Biodiversity Net Gain (BNG) Register Scraper

Structured, machine-readable feed of the UK **Biodiversity Net Gain (BNG) sites register** —
every registered biodiversity gain site, its habitat units, local planning authority (LPA)
allocations, and responsible body, pulled from the official Defra Biodiversity Net Gain data
API. Free and public.

**Keywords:** biodiversity net gain, BNG, BNG credits, habitat bank, habitat banking, gain site
register, biodiversity units, habitat units, Natural England, Defra, NSIP, Nationally
Significant Infrastructure Projects, UK planning, local planning authority, LPA, statutory
biodiversity metric, Town and Country Planning Act, environmental due diligence.

### Why this actor exists

England's Environment Act 2021 makes **mandatory 10% biodiversity net gain** a condition of
most planning permissions (since February 2024 for major developments, April 2024 for small
sites) and — from **2 November 2026** — for **Nationally Significant Infrastructure Projects
(NSIPs)** too. Every registered gain site and every habitat-unit credit sale is recorded on the
government's "biodiversity gain sites register," but that register is published only as a
manual search UI on GOV.UK:
<https://www.gov.uk/guidance/search-the-biodiversity-gain-sites-register> — searchable one site
at a time, no bulk export, no documented API.

This actor queries the register's own underlying JSON API directly and returns the full dataset
(or a filtered slice) as structured records — one item per gain site.

**Who this is for:** planning consultants and ecologists tracking BNG delivery, habitat bank
operators and credit sellers monitoring competitor supply, developers and their environmental
DD teams checking a site or LPA's registered gain capacity, and AI agents / research tools that
need current UK BNG register data without screen-scraping a JavaScript search box by hand.

### Data source

The GOV.UK search page is a Next.js single-page app. Its page bundle embeds
`"apiUrl":"https://environment.data.gov.uk/bng"` in a `__NEXT_DATA__` JSON payload, and that
host exposes a public Swagger UI at `https://environment.data.gov.uk/bng/swagger`
(spec: `https://environment.data.gov.uk/bng/swagger/v1/swagger.json`) describing a
**"Biodiversity Net Gain API"** with a paginated `GET /bng/api/all` endpoint. This actor calls
that endpoint directly — no API key or authentication is required, and it is the same public
data the GOV.UK search page itself reads. No scraping of rendered HTML is involved.

### Input

| Field | Type | Required | Description |
|---|---|---|---|
| `localPlanningAuthority` | string | No | Free-text filter, case-insensitive substring match against the LPA name(s) recorded on the site's habitat-unit allocations (e.g. `"Leeds"`, `"Buckinghamshire"`). Empty = all authorities. |
| `habitatType` | string | No | Free-text filter, case-insensitive substring match against habitat type names on the site (e.g. `"Lowland meadows"`, `"Woodland"`). Empty = all habitat types. |
| `dateFrom` | string (`YYYY-MM-DD`) | No | Earliest gain-site start (registration) date to include. Empty = no lower bound. |
| `dateTo` | string (`YYYY-MM-DD`) | No | Latest gain-site start (registration) date to include. Empty = no upper bound. Cannot be in the future. |
| `maxRecords` | integer | No | Safety cap on the number of records returned, applied after filtering. Empty = no cap (the register currently holds under 1,000 sites). |

#### Example input

```json
{
  "localPlanningAuthority": "Leeds",
  "habitatType": "",
  "dateFrom": "2024-01-01",
  "dateTo": "",
  "maxRecords": 50
}
```

### Output

One dataset item per biodiversity gain site:

```json
{
  "reference_number": "BGS-060324001",
  "site_size_hectares": 19.74,
  "grid_reference": "SP6532018711",
  "gain_site_status": "Registered",
  "start_date": "2023-08-10T00:00:00",
  "end_date": "2053-08-10T00:00:00",
  "removal_date": null,
  "extract_date": "2026-07-03T13:35:33.1287007",
  "responsible_bodies": ["Buckinghamshire LPA"],
  "local_planning_authorities": ["Buckinghamshire LPA"],
  "planning_references": ["PL/24/2989/FA"],
  "habitat_types": [
    "Grassland - Lowland meadows",
    "Grassland - Other neutral grassland"
  ],
  "land_boundary_url": "https://manage-biodiversity-gains.defra.gov.uk/public-documents/BGS-060324001.jpg",
  "allocation_count": 1,
  "amendment_count": 0,
  "raw": { "...": "full unflattened API record, including per-habitat-parcel area/condition/unit detail and per-allocation developer references" }
}
```

Field notes:

- `reference_number` is the official Biodiversity Gain Site (BGS) reference.
- `site_size_hectares` is the total registered site area.
- `local_planning_authorities` / `planning_references` are drawn from the site's `allocations`
  — a site with no allocations recorded yet (habitat units registered but not yet sold/assigned
  to a specific planning permission) returns empty arrays here, not an error.
- `habitat_types` lists every distinct habitat type recorded on the site (baseline and
  created/enhanced combined) — see `raw.habitats` for the full baseline vs. created-or-enhanced
  breakdown with area, condition, and unit counts per parcel.
- `raw` preserves the complete, unflattened API record for anyone who needs the nested detail
  (hedgerow/watercourse units, per-parcel intervention type, developer references, amendment
  history).

### Pricing

**Free.** This is a market-validation probe: BNG is newly mandatory for NSIPs from 2 November
2026 and no bulk API product for this register currently exists on Apify Store. This actor is
published free to test demand before any paid tier is considered.

### Known limitations / fragility

- **The underlying Defra API is an unversioned public beta**, not a documented, stable
  contract. It was reverse-engineered from a Next.js page bundle and a discoverable Swagger UI,
  not from official API documentation — Defra could change or remove it without notice.
- **Record offsets roughly 90-120 in the register reproducibly fail on the Defra server side.**
  Verified across multiple independent page-size/offset combinations (`pageSize=15` page 7,
  `pageSize=20` page 6, `pageSize=10` page 10) — every request whose window falls in that range
  either times out (45-60s) or returns HTTP 500, regardless of page size. This points to a
  server-side issue with a specific record (or small run of records) in that part of the
  register, not a client pagination-parameter problem. This actor retries each page
  individually with exponential backoff (up to 4 attempts), but if a page keeps failing, the run
  fails with a clear error rather than silently returning a truncated dataset. Set `maxRecords`
  to 90 or fewer (the default) to reliably avoid this range entirely.
- **Large page sizes hang.** `pageSize=100` was observed to time out consistently during
  testing; this actor defaults to `pageSize=15` to keep each request small and each retry cheap.
- **`localPlanningAuthority` / `habitatType` filters are substring matches against whatever
  free-text values the register itself contains** — they are not validated against a fixed
  enum, because the register's own LPA and habitat-type values are not exposed as a stable
  fixed list by the source API.

### Local testing (no Apify account required)

```bash
pip install -r requirements.txt
python -m src.main
```

Reads `test_input.json` from the project root and writes results to `sample_output.json`. No
Apify platform, API key, or account is needed — `src/main.py` detects the Apify runtime via the
`APIFY_IS_AT_HOME` environment variable and falls back to local file I/O when it's absent.

### Legal basis

The biodiversity gain sites register is a statutory public register maintained by Natural
England under the Environment Act 2021 and the Town and Country Planning Act 1990 (as amended).
This actor reads only that public register through its own public API — the same data and
access path available to any member of the public via the GOV.UK search page, at machine scale.

# Actor input Schema

## `localPlanningAuthority` (type: `string`):

Optional free-text filter matched (case-insensitive, substring) against the local planning authority name recorded against each site's habitat-unit allocations (e.g. "Leeds", "Buckinghamshire", "Cornwall LPA"). Leave empty to include all authorities.

## `habitatType` (type: `string`):

Optional free-text filter matched (case-insensitive, substring) against habitat type names recorded on the site (e.g. "Lowland meadows", "Woodland", "Grassland"). Leave empty to include all habitat types.

## `dateFrom` (type: `string`):

Earliest gain-site start date (registration date) to include, ISO format YYYY-MM-DD. Leave empty for no lower bound.

## `dateTo` (type: `string`):

Latest gain-site start date (registration date) to include, ISO format YYYY-MM-DD. Leave empty for no upper bound. Cannot be in the future.

## `maxRecords` (type: `integer`):

Safety cap on the number of gain-site records to return in this run, applied after filtering. Leave empty for no cap and the actor will attempt to walk the entire register, but note: the underlying Defra API reproducibly times out / 500s around record offset ~90-120 regardless of page size — see README 'Known limitations'. A bounded value of 90 or less completes fastest and most reliably today.

## Actor input object example

```json
{
  "localPlanningAuthority": "",
  "habitatType": "",
  "maxRecords": 90
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "maxRecords": 90
};

// Run the Actor and wait for it to finish
const run = await client.actor("vagile_airliner/uk-bng-register-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "maxRecords": 90 }

# Run the Actor and wait for it to finish
run = client.actor("vagile_airliner/uk-bng-register-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "maxRecords": 90
}' |
apify call vagile_airliner/uk-bng-register-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=vagile_airliner/uk-bng-register-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/acts/QTJiitg6xMJEZUyMq/builds/eNVJ1fHwKObuukW95/openapi.json
