gatelogue_types

Python utility library for using Gatelogue data in Python projects. It will load the database for you to access via ORM or raw SQL.

Installation

Run pip install gatelogue-types or uv add gatelogue-types. Or add gatelogue-types to your requirements.txt or pyproject.toml.

To import directly from the repository, run pip install git+https://github.com/mrt-map/gatelogue#subdirectory=gatelogue-types-py or add gatelogue-types @ git+https://github.com/mrt-map/gatelogue#subdirectory=gatelogue-types-py to your requirements.txt or pyproject.toml.

Optionally, you can add an HTTP client (e.g. requests, niquests) of your choice.

Usage

To retrieve the data:

import gatelogue_types as gt  # for convenience

gd = gt.GD.get()  # retrieve data via `urllib` (in standard library)
gd = gt.GD.get(
    getter=GD.Getters.niquests
)  # retrieve data with pre-written `niquests` getter
gd = await gt.GD.get_async(
    getter=GD.Getters.aiohttp
)  # same but async with pre-written `aiohttp` getter
gd = await gt.GD.get(
    getter=lambda url: requests.get(url).content
)  # custom getter. all getters take one `str` and output a `byte`

# for both .get() and .get_async(), you can make it retrieve a version with sources.
gd = gt.GD.get(sources=True)

Using the ORM does not require SQL and makes for generally clean code. However, doing this is very inefficient as each attribute access is one SQL query.

for airport in gd.nodes(gt.AirAirport):
    for gate in airport.gates:
        print(f"Airport {airport.code} has gate {gate.code}")

Querying the underlying SQLite database directly with sqlite3 is generally more efficient and faster. It is also the only way to access the *Source tables, if you retrieved the database with those.

for airport_code, gate_code in gd.conn.execute(
    "SELECT A.code, G.code FROM AirGate G INNER JOIN AirAirport A ON G.airport = A.i"
).fetchall():
    print(f"Airport {airport.code} has gate {gate.code}")

Note that gatelogue-types (py) is used by gatelogue-aggregator, which is why many classes have methods for modifying the database. Usage of these methods are discouraged. These are not used in normal use 99% of the time, and they will probably error anyway.

Classes

GD([database])

Main class that contains an sqlite3.Connection

Modules

air

bus

node

rail

sea

spawn_warp

town