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.2.0 wheel into another environment:
uv build
uv pip install dist/chile_dtpm_gtfs-0.2.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 their applicability.
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. Generic
feed.select(route_types=frozenset({...})) uses the same relational pipeline.
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
- Documentation home and API reference
- Downloads, GTFS loading, Metro, and GeoJSON
- Roadmap, changelog, and release guide
- Contributing, security policy, and code of conduct
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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chile_dtpm_gtfs-0.2.0.tar.gz | 103.1 kB | With provenance | Details for chile_dtpm_gtfs-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chile_dtpm_gtfs-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for chile_dtpm_gtfs-0.2.0-py3-none-any.whl |
Total release size: 139.5 kB
Release files / chile_dtpm_gtfs-0.2.0.tar.gz
| Download URL | chile_dtpm_gtfs-0.2.0.tar.gz |
|---|---|
| Size | 103.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4054c5602c25fd9c23aa8c210bdcdb284646c3f6f6e2faed56382f395e89548a
|
|
BLAKE2b-256 checksum How to use checksums |
83c98390fe4fbc1f8d868c8d709beabfc91c21121e75def41cf991338a7356ae
|
| 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 logRelease files / chile_dtpm_gtfs-0.2.0-py3-none-any.whl
| Download URL | chile_dtpm_gtfs-0.2.0-py3-none-any.whl |
|---|---|
| Size | 36.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
546fb1b9c70e7f1a1cdc1dffc26499b9d625291d32defbb04a44f202daf0f03f
|
|
BLAKE2b-256 checksum How to use checksums |
3891c93757e2c5cb89fa95a72202e77fe2353ebfe79827a782ff04c89db7bf90
|
| 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 logSecurity for chile-dtpm-gtfs 0.2.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.
Attestation for chile_dtpm_gtfs-0.2.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 logA 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.