Library API¶
The public Python API mirrors the web API: three entry points —
render, analyze, validate — that take the same names and arguments (but run
synchronously). Import everything from the top-level gpxsheet package:
import gpxsheet
# render a map (portrait PDF is the default; layouts and formats below)
gpxsheet.render("route.gpx", "route.pdf")
gpxsheet.render("route.gpx", "overview.png", layout="preview", format="png")
# structured analysis
route = gpxsheet.analyze("route.gpx", fuel_range=180)
# validation report (route + findings)
report = gpxsheet.validate("route.gpx", fuel_range=180)
for f in report.findings:
print(f.level, f.code, f.message)
OSM enrichment runs as part of analysis, falling back to the geometry baseline when a route is too sparse to sample or the Overpass query fails.
Render¶
layout (portrait · landscape · preview · strip) and format (pdf ·
png) are independent; portrait PDF is the default.
gpxsheet.render ¶
render(gpx_file: str, output_file: str | None = None, *, profile: str = DEFAULT_PROFILE, fuel_range: float | None = None, layout: str = 'portrait', format: str = 'pdf', turn_style: str = 'stylized', paper: str = 'letter', lanes_per_page: int = 4, decisions_per_lane: int | None = None) -> str
Render a GPX route to a tank-bag navigation map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gpx_file
|
str
|
Path to the input |
required |
output_file
|
str | None
|
Output path; defaults to |
None
|
profile
|
str
|
One of |
DEFAULT_PROFILE
|
fuel_range
|
float | None
|
Rider fuel range in miles, used for fuel-gap analysis. |
None
|
layout
|
str
|
|
'portrait'
|
format
|
str
|
|
'pdf'
|
turn_style
|
str
|
Strip bend style, |
'stylized'
|
paper
|
str
|
Page size for paginated PDF layouts, |
'letter'
|
lanes_per_page
|
int
|
|
4
|
decisions_per_lane
|
int | None
|
max decisions per page/lane for the paginated layouts
( |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The path to the written file. |
Source code in src/gpxsheet/__init__.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
Analyze¶
gpxsheet.analyze ¶
analyze(gpx_file: str, *, profile: str = DEFAULT_PROFILE, fuel_range: float | None = None, reassurance_interval: float | None = None, include_hazards: bool = False) -> Route
Run the route analysis engine on a GPX file.
Loads the GPX, runs decision-point detection, reassurance-marker placement,
fuel analysis and segmentation, and returns the populated :class:Route.
include_hazards adds OSM hazard data for validation. See the analyze
output mode in docs/product.md.
Source code in src/gpxsheet/__init__.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
Validate¶
gpxsheet.validate ¶
Route validation (the validate output mode in docs/product.md).
Reports hazards/warnings for a route: fuel gaps exceeding the rider's range,
unpaved stretches, and ferry crossings. Operates on an already-analyzed
:class:~gpxsheet.models.Route; the unpaved/ferry checks need OSM data
(analyze(..., include_hazards=True)), and degrade to a "skipped" note when OSM
data isn't available (osmnx missing, sparse route, or Overpass failure).
ValidationReport
dataclass
¶
An analyzed route plus its validation findings (returned by validate).
Source code in src/gpxsheet/validate.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
format_findings ¶
format_findings(route: Route, findings: list[Finding]) -> str
Human-readable validation report.
Source code in src/gpxsheet/validate.py
104 105 106 107 108 109 110 111 112 113 114 115 116 | |
validate_route ¶
validate_route(route: Route, *, fuel_range: float | None = None) -> list[Finding]
Return validation findings for an analyzed route.
Source code in src/gpxsheet/validate.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
gpxsheet.ValidationReport
dataclass
¶
An analyzed route plus its validation findings (returned by validate).
Source code in src/gpxsheet/validate.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
gpxsheet.Finding
dataclass
¶
Source code in src/gpxsheet/validate.py
23 24 25 26 27 | |
Lower-level helpers¶
gpxsheet.load_route ¶
load_route(gpx_file: str, *, name: str | None = None) -> Route
Load a GPX file into a :class:Route without running analysis.
Source code in src/gpxsheet/__init__.py
135 136 137 138 139 | |
gpxsheet.analyze_route ¶
analyze_route(route: Route, **kwargs) -> Route
Run analysis on an already-loaded :class:Route (see :mod:gpxsheet.analysis).
Source code in src/gpxsheet/__init__.py
142 143 144 145 146 | |
Route model¶
The analysis returns a populated Route. These are the dataclasses you'll read
off it.
gpxsheet.models.Route
dataclass
¶
The full analyzed route graph.
Source code in src/gpxsheet/models.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
gpxsheet.models.DecisionPoint
dataclass
¶
A navigation decision along the route.
Source code in src/gpxsheet/models.py
62 63 64 65 66 67 68 69 70 71 72 73 74 | |
gpxsheet.models.Segment
dataclass
¶
A named stretch of road between transitions.
Source code in src/gpxsheet/models.py
142 143 144 145 146 147 148 149 150 151 152 | |
gpxsheet.models.FuelStop
dataclass
¶
A fuel opportunity on or near the route.
Source code in src/gpxsheet/models.py
88 89 90 91 92 93 94 95 | |
gpxsheet.models.GeoPoint
dataclass
¶
A single route vertex.
Source code in src/gpxsheet/models.py
20 21 22 23 24 25 26 | |