# GTFS Feed Extractor (`datamule/gtfs-feed-extractor`) Actor

Point at ANY GTFS-static feed URL (BART, MBTA, and thousands of transit agencies worldwide — one global standard) and get flat dataset rows: agency, stops, routes, trips, calendar, stop\_times and more. Discovery mode lists a feed's tables. Pay per record.

- **URL**: https://apify.com/datamule/gtfs-feed-extractor.md
- **Developed by:** [Datamule](https://apify.com/datamule) (community)
- **Categories:** Travel
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.35 / 1,000 records

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use 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

## GTFS Feed Extractor

**Point at ANY GTFS-static feed URL and get flat, structured dataset rows — one actor for every transit agency on Earth.**

GTFS (the **General Transit Feed Specification**, originally Google Transit) is *the* single global standard for public-transit schedule data. Thousands of agencies on every continent — subways, buses, trams, ferries, rail — publish the identical **ZIP-of-CSVs**: `agency.txt`, `stops.txt`, `routes.txt`, `trips.txt`, `stop_times.txt`, `calendar.txt`, `calendar_dates.txt`, `shapes.txt`, `fare_*.txt`, `feed_info.txt` and more.

Every other "transit" scraper wraps **one** agency. This actor is the **generic runner**: give it any GTFS-static ZIP URL and it turns the tables you ask for into dataset rows — one row per CSV record, the columns preserved exactly, plus a lossless copy of each original record.

### What it does

- **Extract mode (default):** downloads the feed ZIP and parses the tables you choose into flat rows. Each row carries the CSV columns as-is, plus meta columns `_table` (which file), `_feed_url`, `_row` (0-based index in the table), and `_raw` (the verbatim original record).
- **Discovery mode (`listTablesOnly`):** emits one row per table the feed contains — its name, row count and column names — so you can see what a feed holds before pulling the big tables.

Robust to real-world feed variation: it matches table names case-insensitively against whatever the ZIP actually contains, parses with a proper CSV reader (quoted fields, embedded commas), strips UTF-8 BOMs, tolerates non-UTF-8 feeds and non-standard extension columns, and **skips missing tables silently** instead of crashing.

### Input

| Field | Type | Description |
|-------|------|-------------|
| `gtfs_url` *(required)* | string | Direct URL to a GTFS-static ZIP feed, e.g. `https://www.bart.gov/dev/schedules/google_transit.zip`. |
| `tables` | array | Tables to extract, by name (with or without `.txt`): `stops`, `routes`, `trips`, `calendar`… Leave empty for a sensible default set (`agency`, `feed_info`, `calendar`, `calendar_dates`, `routes`, `stops`, `trips` — **not** `stop_times`, which is often 100k+ rows). Use `["all"]` to extract every table including `stop_times`/`shapes`. |
| `maxRecords` | integer | Optional **global** cap on rows emitted across *all* requested tables. Keeps a sample cheap. |
| `listTablesOnly` | boolean | Discovery mode — list the feed's tables (name, row count, columns) instead of extracting. |
| `bearer` | string (secret) | Optional bearer token for gated feeds. Never logged. |
| `extraHeaders` | object | Optional extra HTTP headers for gated feeds, e.g. `{"x-api-key": "…"}`. Never logged. |

### Output

One dataset item per CSV record. For a `stops` row from BART, for example:

```json
{
  "_table": "stops",
  "_feed_url": "https://www.bart.gov/dev/schedules/google_transit.zip",
  "_row": 0,
  "stop_id": "A10-1",
  "stop_code": "902101",
  "stop_name": "Lake Merritt",
  "stop_lat": "37.797296",
  "stop_lon": "-122.265287",
  "zone_id": "LAKE",
  "location_type": "0",
  "parent_station": "LAKE",
  "_raw": { "stop_id": "A10-1", "stop_code": "902101", "stop_name": "Lake Merritt", "…": "…" }
}
````

Empty CSV cells become `null` in the flat columns; `_raw` preserves the verbatim record (including any values beyond the header).

### Finding feeds

Almost every public agency's GTFS feed is cataloged in the **MobilityData Mobility Database** (<https://mobilitydatabase.org>), the ~2,000-feed successor to TransitFeeds. Point this actor at any feed's direct download URL.

### Pricing

Pay-per-event: **$0.0005 per record** (one emitted dataset row). Use `maxRecords` and a focused `tables` list to control cost — you rarely need every row of `stop_times`.

### Notes & limits

- **GTFS-static only.** GTFS-Realtime (the protobuf `.pb` trip-update/vehicle-position feeds) is a different format and is not covered here.
- Feeds up to 512 MB are supported; larger feeds should be sampled with `maxRecords` / `tables`.
- A URL that 404s or isn't a ZIP returns a clear error; a feed missing an optional table simply skips it.

# Actor input Schema

## `gtfs_url` (type: `string`):

A direct URL to a GTFS-static ZIP feed — the single global public-transit standard, published by thousands of agencies worldwide as an identical zip-of-CSVs. Example: https://www.bart.gov/dev/schedules/google\_transit.zip (Bay Area Rapid Transit). Find feeds for almost any agency via the MobilityData Mobility Database (mobilitydatabase.org).

## `tables` (type: `array`):

Which GTFS tables (files) to extract, by name (with or without .txt): e.g. stops, routes, trips, calendar. Leave EMPTY for a sensible default set (agency, feed\_info, calendar, calendar\_dates, routes, stops, trips — deliberately NOT stop\_times, which is often 100k+ rows). Use a single entry "all" to extract every table in the feed (including the large stop\_times and shapes). Names not present in the feed are skipped silently.

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

Optional GLOBAL cap on the number of rows emitted across ALL requested tables (each emitted row is one billable record). stop\_times alone can be 100k+ rows, so a cap keeps a sample cheap. Default 25; set a larger value only when you intentionally want a broader extraction.

## `listTablesOnly` (type: `boolean`):

When on, ignore "Tables to extract" and instead emit one row per table the feed contains — its name, row count and column names. A cheap way to inspect what a feed holds before pulling the big tables.

## `bearer` (type: `string`):

Optional bearer token for gated feeds (sent as Authorization: Bearer \*\*\*). Not required for public GTFS feeds. Never logged.

## `extraHeaders` (type: `object`):

Optional extra HTTP headers as a JSON object, e.g. {"x-api-key": "..."} for gated feeds. Not required for public feeds. Header values are never logged.

## Actor input object example

```json
{
  "gtfs_url": "https://www.bart.gov/dev/schedules/google_transit.zip",
  "tables": [
    "agency",
    "stops",
    "routes",
    "trips"
  ],
  "maxRecords": 25,
  "listTablesOnly": false
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# 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 = {
    "gtfs_url": "https://www.bart.gov/dev/schedules/google_transit.zip",
    "tables": [
        "agency",
        "stops",
        "routes",
        "trips"
    ],
    "maxRecords": 25
};

// Run the Actor and wait for it to finish
const run = await client.actor("datamule/gtfs-feed-extractor").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 = {
    "gtfs_url": "https://www.bart.gov/dev/schedules/google_transit.zip",
    "tables": [
        "agency",
        "stops",
        "routes",
        "trips",
    ],
    "maxRecords": 25,
}

# Run the Actor and wait for it to finish
run = client.actor("datamule/gtfs-feed-extractor").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 '{
  "gtfs_url": "https://www.bart.gov/dev/schedules/google_transit.zip",
  "tables": [
    "agency",
    "stops",
    "routes",
    "trips"
  ],
  "maxRecords": 25
}' |
apify call datamule/gtfs-feed-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=datamule/gtfs-feed-extractor",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "GTFS Feed Extractor",
        "description": "Point at ANY GTFS-static feed URL (BART, MBTA, and thousands of transit agencies worldwide — one global standard) and get flat dataset rows: agency, stops, routes, trips, calendar, stop_times and more. Discovery mode lists a feed's tables. Pay per record.",
        "version": "0.1",
        "x-build-id": "TxoQilCq9IygdUMNp"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/datamule~gtfs-feed-extractor/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-datamule-gtfs-feed-extractor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/datamule~gtfs-feed-extractor/runs": {
            "post": {
                "operationId": "runs-sync-datamule-gtfs-feed-extractor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/datamule~gtfs-feed-extractor/run-sync": {
            "post": {
                "operationId": "run-sync-datamule-gtfs-feed-extractor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "gtfs_url"
                ],
                "properties": {
                    "gtfs_url": {
                        "title": "GTFS-static feed URL",
                        "type": "string",
                        "description": "A direct URL to a GTFS-static ZIP feed — the single global public-transit standard, published by thousands of agencies worldwide as an identical zip-of-CSVs. Example: https://www.bart.gov/dev/schedules/google_transit.zip (Bay Area Rapid Transit). Find feeds for almost any agency via the MobilityData Mobility Database (mobilitydatabase.org)."
                    },
                    "tables": {
                        "title": "Tables to extract",
                        "type": "array",
                        "description": "Which GTFS tables (files) to extract, by name (with or without .txt): e.g. stops, routes, trips, calendar. Leave EMPTY for a sensible default set (agency, feed_info, calendar, calendar_dates, routes, stops, trips — deliberately NOT stop_times, which is often 100k+ rows). Use a single entry \"all\" to extract every table in the feed (including the large stop_times and shapes). Names not present in the feed are skipped silently.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "maxRecords": {
                        "title": "Max records",
                        "minimum": 1,
                        "type": "integer",
                        "description": "Optional GLOBAL cap on the number of rows emitted across ALL requested tables (each emitted row is one billable record). stop_times alone can be 100k+ rows, so a cap keeps a sample cheap. Default 25; set a larger value only when you intentionally want a broader extraction.",
                        "default": 25
                    },
                    "listTablesOnly": {
                        "title": "List tables only (discovery)",
                        "type": "boolean",
                        "description": "When on, ignore \"Tables to extract\" and instead emit one row per table the feed contains — its name, row count and column names. A cheap way to inspect what a feed holds before pulling the big tables.",
                        "default": false
                    },
                    "bearer": {
                        "title": "Bearer token",
                        "type": "string",
                        "description": "Optional bearer token for gated feeds (sent as Authorization: Bearer ***). Not required for public GTFS feeds. Never logged."
                    },
                    "extraHeaders": {
                        "title": "Extra request headers",
                        "type": "object",
                        "description": "Optional extra HTTP headers as a JSON object, e.g. {\"x-api-key\": \"...\"} for gated feeds. Not required for public feeds. Header values are never logged."
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
