from typing import Any from fastapi import APIRouter, Body, Path from location.api import schemas from location.connectors import ip2location from location.types import IPvAnyAddress router = APIRouter(tags=["location"]) @router.get( "/lookup/{ip}", operation_id="lookupIP", response_model=schemas.LookupIPResponse, ) async def lookup(ip: IPvAnyAddress = Path()) -> Any: return await ip2location.lookup(ip) @router.post( "/lookup/batch", operation_id="lookupIPBatch", response_model=dict[IPvAnyAddress, schemas.LookupIPResponse], ) async def lookup_batch( data: schemas.LookupIPBatchRequest = Body(), ) -> Any: return await ip2location.lookup_batch(data.ips, only_resolved=data.only_resolved)