Georepository client¶
geodetic_engine.georepository is an HTTP client for a Georepository geodetic
registry. It was written
against the Georepository OpenAPI document, so it works with any instance, not
just one deployment.
Use it when you want to read a register’s CRSs, datums and transformations
from Python. Custom database from Georepository uses it to build a custom proj.db, but it does not
depend on that.
You do not need it to transform coordinates. Transformations read a
proj.db, never the register.
Not executed
The examples on this page need network access to a Georepository instance and OAuth2 credentials, so they are not run during the documentation build.
Configuration¶
GeorepositoryConfig holds everything
the client needs:
Field |
Default |
Meaning |
|---|---|---|
|
required |
Base URL of the instance |
|
required |
OAuth2 client credentials; see Obtaining OAuth2 credentials |
|
|
Identity server token endpoint |
|
|
Scope the client is granted |
|
|
Objects per page when enumerating a collection |
|
|
Seconds per HTTP request |
|
|
Whether collections include deprecated objects |
The configuration is validated on construction. An invalid one raises
GeorepositoryConfigError.
Reading a collection¶
from geodetic_engine.georepository import GeorepositoryClient, GeorepositoryConfig
config = GeorepositoryConfig(
api_url="https://georepository.example.com",
client_id=..., # from the environment, never from source code
client_secret=...,
)
with GeorepositoryClient(config) as client:
for datum in client.iter_collection("Datum", authorities=frozenset({"YourAuthority"})):
print(datum["Code"], datum["Name"])
iter_collection()
yields every object in a collection endpoint, following pages until the
advertised TotalResults is reached. The API has no server-side authority
filter, so authorities= filters on each object’s DataSource on the client
side.
Other methods fetch detail around a search result:
Method |
Returns |
|---|---|
The full object behind a search result |
|
One object by absolute URL, cached for the client’s lifetime |
|
The object a |
|
An object’s alias records |
|
The object exported as WKT2 |
|
The newest version of each dataset the register holds |
|
The newest version name, for provenance |
Paging is verified¶
A silently truncated list would leave an imported database silently
incomplete. The client raises
PaginationTruncatedError if the server
advertises more results than it returns, or ignores the page parameter.
Retries and trusted origins¶
A request that fails to connect, or returns HTTP 502, 503 or 504, is retried,
up to three attempts. Every request URL, including ones the server returns in
links, must be HTTPS with the same host and port as api_url, and must have no
user-info or fragment. A malicious or misconfigured response therefore cannot
send the bearer token to another host.
Response cache¶
When used by geodetic-projdb, responses are cached in a local SQLite file
next to the output database, so a rebuild does not fetch everything again. The
cache sits below the client as an httpx transport:
Only
GETresponses with status200are cached. The OAuth2 token request is aPOST, so a bearer token never reaches the disk, and a transient502is never stored as an answer.The register’s version history is never cached, because it is what decides whether the rest of the cache is stale.
--no-cache, --refresh-cache and --cache-db on
geodetic-projdb control it.
Obtaining OAuth2 credentials¶
Ask your Georepository administrator for a client credentials registration. You need:
a client id and client secret for a machine account;
the client granted the API scope,
GeoRepositoryAPI_Scopeunless your instance uses another;the token endpoint URL, if it is not
{your-instance}/auth/connect/token.
The Georepository OpenAPI document advertises an implicit flow, which is for
interactive use in a browser. A server-to-server caller like this one uses the
client credentials grant against the identity server.
GeorepositoryCredential requests the
token with HTTP Basic authentication and reuses it until shortly before it
expires.
Errors¶
Exception |
Raised when |
|---|---|
The configuration is invalid |
|
A token cannot be obtained |
|
A request fails, returns something that is not the expected JSON, or points to another origin |
|
Paging returned fewer objects than advertised |
All derive from GeorepositoryError.