Skip to content

Web API

api ¤

fapi ¤

app module-attribute ¤

app = FastAPI(
    title="AM4Tools V2 API (Alpha)",
    description="A collection of calculators and tools for Airline Manager 4, aimed to facilitate statistical analyses and promote the development of third-party tools. This version is primarily rewritten in C++ for performance, in particular, route finding.\n\n**This API is currently in alpha** - please report any issues on our [AM4Tools Discord server](https://discord.gg/4tVQHtf), or ping me at @cathayexpress if you encounter critical issues such as 500 Internal Server Error. This project is open source - feel free to open pull requests on [GitHub](https://github.com/cathaypacific8747/am4).\n\n# Key features\n- Fuzzy airport and aircraft search\n- Basic route details (P2P)\n- Advanced route details (P2P, with aircraft)\n- Automatic best stopover, trips per day and seat algorithm selection\n- Advanced route finder (P2P, with aircraft, origin hub, and filters) - **be careful: the massive response payload may crash this tab**: use Insomnia or Postman instead!\n- Fuel, CO2, misc costs and contribution estimation\n\nAt this stage, **no authentication is required** to access the API. An API token in the future will be required as this scales.\n\nThis service is 100% free to use for all users.\n\nOpen one of the endpoints and click the try it out button right here in your browser, or download `openapi.json` to test it out!",
    version="0.1.8",
    lifespan=lifespan,
)

server module-attribute ¤

server = Server(
    Config(
        app,
        host=HOST,
        port=PORT,
        reload=RELOAD,
        server_header=False,
        log_level=lower(),
    )
)

lifespan async ¤

lifespan(app: FastAPI)

construct_acnf_response ¤

construct_acnf_response(
    param_name: str, ac_sugg: list[Suggestion]
) -> ORJSONResponse
ac_search(query: FAPIReqACSearchQuery)

construct_apnf_response ¤

construct_apnf_response(
    param_name: str, ap_sugg: list[Suggestion]
) -> ORJSONResponse
ap_search(query: FAPIReqAPSearchQuery)

route_info async ¤

route_info(
    origin: FAPIReqAPSearchQuery,
    destination: FAPIReqAPSearchQuery,
)

ac_route_info async ¤

ac_route_info(
    origin: FAPIReqAPSearchQuery,
    destination: FAPIReqAPSearchQuery,
    ac: FAPIReqACSearchQuery,
    options: FAPIReqACROptions,
    user: FAPIReqUser,
)

ac_route_find_routes async ¤

ac_route_find_routes(
    ap0: FAPIReqAPSearchQuery,
    ac: FAPIReqACSearchQuery,
    options: FAPIReqACROptions,
    user: FAPIReqUser,
)

start async ¤

start(db_done: Event)

models ¤

FAPIReqACSearchQuery module-attribute ¤

FAPIReqACSearchQuery = str

FAPIReqAPSearchQuery module-attribute ¤

FAPIReqAPSearchQuery = str

FAPIReqRealism module-attribute ¤

FAPIReqRealism = bool

FAPIRespAircraft ¤

Bases: BaseModel

status class-attribute instance-attribute ¤
status: str = Field('success', frozen=True)
aircraft instance-attribute ¤
aircraft: PyAircraft

FAPIRespAircraftNotFound ¤

Bases: BaseModel

status class-attribute instance-attribute ¤
status: str = Field('not_found', frozen=True)
parameter class-attribute instance-attribute ¤
parameter: str = Field('ac')
suggestions instance-attribute ¤
suggestions: list[PyAircraftSuggestion]

FAPIRespAirport ¤

Bases: BaseModel

status class-attribute instance-attribute ¤
status: str = Field('success', frozen=True)
airport instance-attribute ¤
airport: PyAirport

FAPIRespAirportNotFound ¤

Bases: BaseModel

status class-attribute instance-attribute ¤
status: str = Field('not_found', frozen=True)
parameter class-attribute instance-attribute ¤
parameter: str = Field('ap')
suggestions instance-attribute ¤
suggestions: list[PyAirportSuggestion]

FAPIToken ¤

Bases: BaseModel

access_token instance-attribute ¤
access_token: str
token_type instance-attribute ¤
token_type: str

FAPIRespUser ¤

Bases: BaseModel

status class-attribute instance-attribute ¤
status: str = Field('success', frozen=True)
user instance-attribute ¤
user: PyUser

FAPIRespUserNotFound ¤

Bases: BaseModel

status class-attribute instance-attribute ¤
status: str = Field('not_found', frozen=True)

FAPIRespACRoute ¤

Bases: BaseModel

status class-attribute instance-attribute ¤
status: str = Field('success', frozen=True)
ap_origin instance-attribute ¤
ap_origin: PyAirport
ap_destination instance-attribute ¤
ap_destination: PyAirport
ac instance-attribute ¤
ac: PyAircraft
ac_route instance-attribute ¤
ac_route: PyACRoute

FAPIDestination ¤

Bases: BaseModel

airport instance-attribute ¤
airport: PyAirport
ac_route instance-attribute ¤
ac_route: PyRoute

FAPIRespACRouteFind ¤

Bases: BaseModel

status class-attribute instance-attribute ¤
status: str = Field('success', frozen=True)
destinations instance-attribute ¤
destinations: list[FAPIDestination]

FAPIRespRoute ¤

Bases: BaseModel

status class-attribute instance-attribute ¤
status: str = Field('success', frozen=True)
ap_origin instance-attribute ¤
ap_origin: PyAirport
ap_destination instance-attribute ¤
ap_destination: PyAirport
route instance-attribute ¤
route: PyRoute

FAPIReqACROptions ¤

FAPIReqACROptions(
    config_algorithm: PyACROptionsConfigAlgorithm = None,
    max_distance: PyACROptionsMaxDistance = None,
    max_flight_time: PyACROptionsMaxFlightTime = None,
    tpd_mode: PyACROptionsTPDMode = None,
    trips_per_day_per_ac: PyACROptionsTripsPerDayPerAC = None,
    sort_by: PyACROptionsSortBy = None,
)
config_algorithm instance-attribute ¤
config_algorithm = config_algorithm
max_distance instance-attribute ¤
max_distance = max_distance
max_flight_time instance-attribute ¤
max_flight_time = max_flight_time
tpd_mode instance-attribute ¤
tpd_mode = tpd_mode
trips_per_day_per_ac instance-attribute ¤
trips_per_day_per_ac = trips_per_day_per_ac
sort_by instance-attribute ¤
sort_by = sort_by
to_core ¤
to_core(ac_type: Type) -> Options

FAPIReqUser ¤

FAPIReqUser(
    realism: FAPIReqRealism = None,
    wear_training: int = None,
    repair_training: int = None,
    l_training: int = None,
    h_training: int = None,
    fuel_training: int = None,
    co2_training: int = None,
    fuel_price: int = None,
    co2_price: int = None,
    accumulated_count: int = None,
    fourx: bool = None,
    income_loss_tol: float = None,
    load: float = None,
)
realism instance-attribute ¤
realism = realism
wear_training instance-attribute ¤
wear_training = wear_training
repair_training instance-attribute ¤
repair_training = repair_training
l_training instance-attribute ¤
l_training = l_training
h_training instance-attribute ¤
h_training = h_training
fuel_training instance-attribute ¤
fuel_training = fuel_training
co2_training instance-attribute ¤
co2_training = co2_training
fuel_price instance-attribute ¤
fuel_price = fuel_price
co2_price instance-attribute ¤
co2_price = co2_price
accumulated_count instance-attribute ¤
accumulated_count = accumulated_count
fourx instance-attribute ¤
fourx = fourx
income_loss_tol instance-attribute ¤
income_loss_tol = income_loss_tol
load instance-attribute ¤
load = load
to_core ¤
to_core() -> User