API reference¶
Generated from the source. The docstrings carry the reasoning rather than restating the signatures, so this is the shortest path to why a piece behaves the way it does.
Building pygeoapi programmatically¶
app.pygeoapi.factory ¶
Programmatic construction of the pygeoapi sub-app.
Replaces the import of pygeoapi.starlette_app (module globals built from env+file at import time) with explicit construction from dicts. The execute shim and the route table are adapted from pygeoapi/starlette_app.py (MIT); the parity test tests/test_pygeoapi_route_parity.py keeps them aligned to upstream.
CLIENT_CLOSED_REQUEST = 499 module-attribute ¶
Nginx's status for a request whose client left; no client is there to read it.
ConfigValidationError ¶
normalize_config(config) ¶
Validate the configuration, then fill the keys the runtime assumes.
Mutates and returns the given dict: callers (including the reload path) share one config object, and pygeoapi copies it internally anyway. Only absent keys are filled — a tenant's own values stay.
Validation lives here rather than in the loader because loading a document and vouching for it are different jobs: the loader is asked for partial documents on purpose. This function is the boundary where a document becomes a configuration something is built from, and both build_openapi and build_api come through it, so boot, reload and CLI are covered without anyone having to remember.
It validates the effective configuration — after ${VAR} interpolation. The source document is a different thing: port: ${PORT} is a string where the schema wants an integer, and rejecting it would be rejecting a perfectly good deployment.
Source code in app/pygeoapi/factory.py
build_openapi(config) ¶
Generate the OpenAPI in memory, with the fastgeoapi fixes at the source.
The document goes through the openapi-pydantic model once: validated, corrected, dumped.
Source code in app/pygeoapi/factory.py
build_api(config, openapi) ¶
pygeoapi's API instance, with no file nor env var in between.
Also drops pygeoapi's translated-config cache. l10n.translate_struct memoises the config it hands to the HTML templates in a MODULE-level dict keyed by locale, so after a reload swap the browser would keep seeing config-derived values (the site title, the item-limit options) from the previous config while JSON already served the new one. A new API instance means a new config, so the cache must go with it.
Source code in app/pygeoapi/factory.py
execute(api, api_function, request, *args, skip_valid_check=False) async ¶
Adaptation of execute_from_starlette with an explicit API instance.
Source code in app/pygeoapi/factory.py
build_routes(api, specs=None, http_cache=None) ¶
The route table, closed over the api instance.
Adapted 1:1 from pygeoapi/starlette_app.py (admin excluded: in its place fastgeoapi has the reload webhook). Every entry is tagged with its spec group (ADR-0005): specs=None returns the COMPLETE table — the coverage contract the parity test checks against upstream — while the sub-app mounts only the active groups. http_cache gives the map and tile routes their cache headers; None sends none.
Source code in app/pygeoapi/factory.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 | |
build_pygeoapi_subapp(config, openapi, *, http_cache=None, pages=None) ¶
Complete Starlette sub-app, same shape as the former APP import.
Mounts only the spec groups the config activates (ADR-0005): the reload webhook rebuilds the sub-app, so the mounted set follows every config update. http_cache defaults to the policy of fastgeoapi's settings. pages serves fastgeoapi's own HTML pages and their compiled assets under /_html; None takes the choice of the settings, which keep pygeoapi's pages by default.
Source code in app/pygeoapi/factory.py
The storage layer¶
app.provider.storage.factory ¶
Store factory: from a source reference to the right backend.
load_store is the factory (in the spirit of pygeoapi's load_plugin): it maps a base — an s3:///gs:///az:/// file:// URL or a local directory — to the right backend. Credentials come ONLY from each cloud's standard environment variables (for Tigris: AWS_ENDPOINT_URL_S3 from the Fly secrets).
split_source(source) ¶
Split an object reference into (base, relative key).
Source code in app/provider/storage/factory.py
is_remote(source) ¶
Whether source names an object across a network: a bucket key or an http(s) URL.
obstore_options(store_options, base='') ¶
store_options spelled for obstore, as :func:load_store builds a store with them.
load_store(base, store_options=None) ¶
Build the backend for a base URL/directory.
store_options are the cloud store settings — region, skip_signature for public data, endpoint for an S3-compatible service (and an explicit one wins over the process environment). They are meaningless for a local path and ignored there.
Source code in app/provider/storage/factory.py
app.provider.storage.ranges ¶
Byte ranges of one object: the seam between a format's parser and the storage layer.
A format read by ranges (PMTiles, COG, FlatGeobuf) only needs "these bytes at this offset". :class:ByteRanges is that contract, with a sync and an async side; :class:ObjectRanges binds it to one key of an :class:ObjectStore, so the parser never learns about buckets.
ByteRanges ¶
Bases: Protocol
Ranged reads over one object, sync and async.
Source code in app/provider/storage/ranges.py
ObjectRanges ¶
:class:ByteRanges over key in store.
Source code in app/provider/storage/ranges.py
SingleFlightRanges ¶
A :class:ByteRanges wrapper: identical awaited reads in flight share one fetch.
Fifty tile requests arriving together on a cold provider each want the same header, root and leaf directories; without this they read them fifty times (measured on Overture: 245 ranged reads for 50 tiles instead of 58). This is de-duplication of what is in flight, not a cache: a later identical read fetches again. Flights are kept per event loop; the synchronous side passes straight through.
Source code in app/provider/storage/ranges.py
read(offset, length) ¶
read_many(ranges) ¶
aread(offset, length) async ¶
Await the fetch already in flight for this range, or start it.
Source code in app/provider/storage/ranges.py
aread_many(ranges) async ¶
Async ranged reads, untouched: batches are unique by construction.
Providers with two faces¶
app.provider.base ¶
The async surface fastgeoapi adds beside pygeoapi's provider contract (ADR-0010).
pygeoapi's contract is synchronous and lives in its root classes (BaseProvider, BaseTileProvider): the API layer reads attributes off the instance and calls the sync methods from a threadpool. This module does not import pygeoapi. It adds the async part only, and the concrete provider pairs the two::
class TilesProvider(AsyncProviderMixin, StorageBackedMixin, BaseTileProvider):
native_async = True
The mixin must come FIRST in the bases: pygeoapi's roots never call super().__init__, so placed after them its __init__ would not run and provider_def would never be captured.
AsyncProviderMixin ¶
The async part, and nothing else.
native_async is a declaration, never an inspection: a provider that awaits its I/O for real sets it to True and writes the async twins (a + the sync method's name: aget_tiles, aquery). Everyone else keeps the default and is served through a thread by :func:async_view.
Source code in app/provider/base.py
run_sync(fn, /, *args, **kwargs) async ¶
Run a blocking callable in the default executor and await its result.
AsyncView ¶
An awaitable face over any provider, native or not.
await async_view(p).get_tiles(...) resolves to p.aget_tiles when p declares native_async and has the twin, and to asyncio.to_thread(p.get_tiles, ...) otherwise. Signatures are the synchronous ones, one to one. Works on providers that never saw the mixin: native_async is read with a default.
Source code in app/provider/base.py
native property ¶
Whether the provider declared itself natively asynchronous.
__getattr__(name) ¶
The coroutine for name: the provider's twin, or its sync method in a thread.
Source code in app/provider/base.py
StorageBackedMixin ¶
A store and byte ranges for the provider's data URL, via the storage layer.
Reads data and store_options from the provider_def that :class:AsyncProviderMixin captured: pygeoapi's roots do not keep the definition, and store_options is not one of the attributes they set. No provider imports obstore (ADR-0003).
Source code in app/provider/base.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 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 191 192 193 194 195 196 197 198 199 200 201 202 | |
store cached property ¶
The object store for the directory or bucket prefix holding data.
cached_ranges cached property ¶
Cached, versioned ranged reads of data, when the range cache applies.
native_store property ¶
The library-level store object, for libraries that read through obstore themselves.
async-tiff is the model: it takes an obstore store and the key of the object and performs its own ranged reads. When the backend exposes no such object the store itself is returned.
object_key property ¶
The key of the data object within :attr:store.
byte_ranges() ¶
range_cache() ¶
Cache for ranged reads of data; None for local data or range_cache: false.
Source code in app/provider/base.py
signed_url(expires_in) ¶
A presigned URL of the data object, for a reader outside this process.
The reader fetches the object over HTTP with the URL alone, and the credentials stay with the store.
Source code in app/provider/base.py
definition_digest() ¶
A digest of the provider's definition: any option that shapes the output changes it.
The definition may carry credentials in store_options; only the digest leaves this method.
Source code in app/provider/base.py
adata_version() async ¶
The version of the data object, the same in every process; None when unknown.
A remote object read through the range cache has the ETag the cache knows, checked again behind the request once its TTL has passed. A remote object read without the cache has none: a HEAD for every request would cost more than the cache saves. A local file has its size and modification time, since its ETag names the inode, which differs from machine to machine.
Source code in app/provider/base.py
app.provider.sansio ¶
Sans-I/O cores and the two drivers that feed them (ADR-0010, decision 6).
A core is a generator: it yields (offset, length) requests, receives the bytes, and returns its result. It knows nothing about where the bytes come from, so it is tested once, in memory, and gives a provider both faces for free::
def get_tiles(...):
return drive_sync(self._tile(z, x, y), self.ranges)
async def aget_tiles(...):
return await drive(self._tile(z, x, y), self.ranges)
Request = tuple[int, int] ¶
One ranged read: (offset, length).
Core = Generator[Request, bytes, T] ¶
A parser step machine: yields requests, receives bytes, returns T.
drive_sync(core, ranges) ¶
Run core to completion with synchronous reads.
Source code in app/provider/sansio.py
drive(core, ranges) async ¶
Run core to completion with awaited reads; no thread involved.
Source code in app/provider/sansio.py
app.interfaces.providers ¶
Provider capability Protocols (ADR-0010).
pygeoapi's provider contract is synchronous and per family. These Protocols describe the asynchronous capability a provider may add, again per family, and are what the router checks::
isinstance(p, AsyncTileProvider) and p.native_async
Conformance is structural: any object with these members qualifies, whether or not it inherits from fastgeoapi's mixin.
AsyncTileProvider ¶
Bases: Protocol
A tile provider that can be awaited for tile data.
Attributes:
| Name | Type | Description |
|---|---|---|
native_async | bool |
|
format_type | str | The configured tile format name ( |
Source code in app/interfaces/providers.py
AsyncFeatureProvider ¶
Bases: Protocol
A feature provider that can be awaited for queries and single items.
Source code in app/interfaces/providers.py
aquery(**kwargs) async ¶
AsyncMapProvider ¶
Bases: Protocol
A map provider that can be awaited for a rendered map.
Source code in app/interfaces/providers.py
VersionedProvider ¶
Bases: Protocol
A provider that tells which version of its answer a request would get.
The HTTP cache builds its ETag from that version before any work is done for the request.
Source code in app/interfaces/providers.py
aversion(**kwargs) async ¶
A string that changes whenever the answer to kwargs changes; None when unknown.
Takes the arguments of the provider's data method, and neither draws nor reads data to answer.
Source code in app/interfaces/providers.py
app.pygeoapi.api_async.tiles ¶
Tile data served with await when the provider is natively async (ADR-0010, decision 5).
Mirrors pygeoapi/api/tiles.py::get_collection_tiles_data step by step: same format check, same headers, same 204 on a missing tile, same 404 on ProviderTileNotFoundError, same generic mapping through api.get_exception. The one difference is that the provider is awaited on the event loop instead of being called in the threadpool.
native_tile_provider(api, dataset) ¶
The collection's tile provider definition and instance, when native async.
Returns None for unknown collections, collections without a tile provider, providers that fail to build and providers that are not native: every one of those keeps pygeoapi's own handler, which answers exactly as before. Instantiation goes through pygeoapi.plugin.load_plugin, the cached one after patch_load_plugin, so a THREAD_SAFE provider is built once.
Source code in app/pygeoapi/api_async/tiles.py
get_collection_tiles_data(api, request, dataset, matrix_id, z, y, x, provider_def, provider, http_cache=None) async ¶
(headers, status, content) for one tile, awaiting the provider.
With http_cache, a provider that knows its version gives the tile an ETag, and a request that names it gets a 304 without the tile being read.
Source code in app/pygeoapi/api_async/tiles.py
The configuration editor¶
app.editor.inspect ¶
Answer three questions about a configuration document.
Is the document being edited well formed? Is what will actually run well formed? Does it build?
These are deliberately plain functions over text, not endpoints: the CLI wants them, a CI check wants them, and the editor's routes are only one caller. Text rather than a parsed mapping because the distinction between source and effective lives in how the text is loaded — pygeoapi resolves ${VAR} at load time, so a mapping has already lost the difference.
Outcome dataclass ¶
What was asked, and what can be said about it.
Attributes:
| Name | Type | Description |
|---|---|---|
ok | bool | Whether the question came back clean. |
problems | list[str] | One line per problem, phrased for whoever wrote the document — the key at fault and why, never a stack trace. |
variables | dict[str, str] | The |
collections | list[str] | For a dry run, the collections that actually stood up. |
specs | list[str] | With |
tools | list[str] | With |
not_reported | list[str] | Parts of an augmented answer that could not be produced, and why. Asking for more than is installed is not an error — saying nothing about it would be. |
Source code in app/editor/inspect.py
validate_source(text) ¶
Check the document as written, placeholders and all.
Source code in app/editor/inspect.py
validate_effective(text) ¶
Check what would actually run, once the placeholders are resolved.
Source code in app/editor/inspect.py
dry_run(text, augmented=False) ¶
Build the configuration for real, and report what stood up.
This is what validation cannot do: a document can satisfy the schema and still name a file that is not there, a provider that will not import, or a bucket nothing can reach.
With augmented, it also reports what fastgeoapi would make of the document beyond serving it: which specifications get mounted, and which MCP tools an agent would see. Both are answers pygeoapi has no way to give — and both are optional, because this command has to keep working for someone who only has pygeoapi.
It answers "does this build here", never "will this work in production": the build uses the environment and the credentials of whoever is running the editor. variables carries what was substituted so a reader can tell the difference — an outcome that hid it would invite reading a green as a guarantee it cannot give.
Source code in app/editor/inspect.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |