Skip to main content

chile-dtpm-gtfs

An unofficial Python library for discovering, downloading, loading, and exporting GTFS data published by Chile's Directorio de Transporte Público Metropolitano (DTPM). GTFS is the General Transit Feed Specification, a format for transit schedules and geographic information.

This project specializes in the DTPM distribution for Santiago. It represents the whole feed, with Metro as the first normalized subset. It is not affiliated with or endorsed by DTPM. The library code is MIT-licensed; that license does not grant rights to upstream transit data.

Installation

Python 3.12+ is required. For development from this checkout:

uv sync --locked
uv run chile-dtpm-gtfs --version

To install a locally built v0.6.0 wheel into another environment:

uv build
uv pip install dist/chile_dtpm_gtfs-0.6.0-py3-none-any.whl

A local build does not imply that this version has been published on PyPI.

Discover the current feed

from chile_dtpm_gtfs import DTPM

dtpm = DTPM()
publications = dtpm.publications()
publication = dtpm.current()
print(publication.title)
print(publication.effective_from)
print(publication.download_url)

Discovery reads the official DTPM index. It uses the published ZIP href, never a filename constructed from a date. current() returns metadata without downloading the archive. Future publications are excluded using today's date in America/Santiago; current(on=date(...)) allows an explicit applicability date. Equal dates retain page order. Special service descriptions are preserved without guessing applicability windows; only the source's explicit effective date controls selection.

Download, select Metro, and export GeoJSON

from chile_dtpm_gtfs import DTPM

publication = DTPM().current()
with publication.download() as feed:
    print(feed.metadata.sha256)
    metro = feed.metro()
    metro.write_geojson("metro.geojson")

Downloads stream to temporary storage, which the context manager removes. Use publication.download(destination="GTFS.zip") to retain the archive. Existing archives are not replaced. Network requests support configurable timeouts and explicit errors; downloads expose SHA-256 and available HTTP size metadata.

Offline and pinned sources

from chile_dtpm_gtfs import GTFSFeed

with GTFSFeed.from_file("GTFS.zip") as feed:
    print(feed.validate().row_counts)
    metro = feed.metro()

# A normalized snapshot remains usable after closing the feed.
geojson = metro.to_geojson()
metro.write_geojson("metro.geojson", overwrite=True)

# An explicit URL bypasses publication discovery.
with GTFSFeed.from_url("https://example.org/feed.zip") as feed:
    print(feed.metadata)

Keep local files unchanged until the feed is closed. Loading validates required files, headers, and feed_info metadata without reading every large table into memory. validate() fully scans CSV records and service time syntax. This is basic validation, not a complete GTFS compliance validator. Its report includes core value/reference diagnostics, and the CLI exits nonzero when such errors are found.

Normalized data

metro() follows routes -> trips -> stop_times -> stops and declared station hierarchies. It selects standard subway route_type=1, never names containing "Metro". Its immutable snapshot exposes agencies, routes, trips, stops, stop_times, shapes, and services, plus station/platform/entrance views. All shape variants and trip directions survive. GTFS times such as 25:10:00 become service seconds.

Use metro(on=date(...)) for calendar-based service filtering; calendar_dates exceptions override weekly calendars. Frequency trips remain templates by default; expand_frequencies=True expands exact-time frequency windows. Generic feed.bus() and feed.rail() convenience selectors use documented GTFS route types and the same relational pipeline as metro(). Use feed.select(route_types=frozenset({...})) for explicit or extended types. Optional advanced tables remain accessible through feed.rows("pathways.txt") and related table names. Missing optional tables yield no rows.

GeoJSON uses original WGS84 [longitude, latitude] coordinates and preserves each route/shape combination. Missing geometry is null; station hierarchies and lines are not invented or visually simplified.

CLI

Prefix with uv run when working from this checkout:

chile-dtpm-gtfs publications
chile-dtpm-gtfs current
chile-dtpm-gtfs download --output GTFS.zip
chile-dtpm-gtfs validate GTFS.zip
chile-dtpm-gtfs export metro --input GTFS.zip --format geojson --output metro.geojson

Discovery, download, and validation output JSON. Export prints the written path. python -m chile_dtpm_gtfs also works. See the CLI guide for options.

Provenance and limitations

Metadata preserves the requested/resolved URL, source page, advertised effective date, original filename, UTC download timestamp, byte count, and SHA-256 when available. Internal feed_start_date/feed_end_date/feed_version remain separate from publication dates. GeoJSON carries this metadata. Local loading computes a hash but cannot reconstruct the original download source; retain download metadata alongside archives when reproducibility matters.

There is no stale-feed fallback or cache. Source layout changes raise explicit errors and may require a parser update. Missing calendars prevent date filtering when applicability cannot be determined. Advanced pathways/levels, frequency expansion, TopoJSON, and runtime JSON are deferred. Selecting large subsets can require substantial memory even though stop_times input is streamed. The source and format contracts are documented in the architecture.

Documentation and development

uv run python -m pytest
uv run python -m ruff check .
uv run python -m ruff format --check .
uv run python -m mypy src
uv run --group docs mkdocs build --strict

Normal tests use generated ZIPs, HTML fixtures, and mocked HTTP. The live acceptance test is opt-in; see testing. Code, docstrings, documentation, and Conventional Commit messages are written in English.

Metadata

Release files for chile-dtpm-gtfs 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chile-dtpm-gtfs 0.6.0
File Size Uploaded Provenance Actions
chile_dtpm_gtfs-0.6.0.tar.gz 107.7 kB With provenance Details for chile_dtpm_gtfs-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chile-dtpm-gtfs 0.6.0
File Interpreter ABI Platform Actions
chile_dtpm_gtfs-0.6.0-py3-none-any.whl Python 3 none any Details for chile_dtpm_gtfs-0.6.0-py3-none-any.whl

Total release size: 146.3 kB

Release files / chile_dtpm_gtfs-0.6.0.tar.gz

Download URL chile_dtpm_gtfs-0.6.0.tar.gz
Size 107.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f6258c83512682735b0c6389caf504d30a75f0fadab960e654a3b30db192dac4
BLAKE2b-256 checksum
How to use checksums
b616edc7580655d6fa8ec64a65a4ab7a1ca26727329dd276e8560fd52af54161
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / chile_dtpm_gtfs-0.6.0-py3-none-any.whl

Download URL chile_dtpm_gtfs-0.6.0-py3-none-any.whl
Size 38.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82629b616363016476f3386ea2435caa4ba74a10595908952807387c31a1d49e
BLAKE2b-256 checksum
How to use checksums
4b91c28a86052e21af0ce66b79ed0fea7948f083cacf2a2c95574f629ec0cbf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Security for chile-dtpm-gtfs 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for chile_dtpm_gtfs-0.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page