fastapi-tile38 icon indicating copy to clipboard operation
fastapi-tile38 copied to clipboard

Interact with Tile38 in-memory geodatabase in your FastAPI


FastAPI-Tile38

Showcase using Tile38 via pyle38 in a FastAPI application.
Report Bug · Request Feature

Table of Contents

  1. About The Project
    • Built With
  2. Getting Started
    • Installation
  3. Usage
  4. License
  5. Contact

About The Project

Showcase of using Tile38 with Pyle38 in a FastAPI application. Can be used as is, or be extended upon with other methods in the pyle38 repertoire of commands.

Built With

Getting Started

Installation

  1. Clone and install
    git clone https://github.com/iwpnd/fastapi-tile38.git
    poetry install
    
  2. Setup environment
    cp .env.dist .env
    
  3. Start your local stack
    docker-compose up
    
  4. Test it!
    pytest . -vv -s
    

Usage

Once the application is started you can checkout and interact with it via on localhost:8001/docs.

Or you can use it with http/curl:

echo '{ "data": { "type": "Feature", "geometry": {"type": "Point", "coordinates": [13.37, 52.25]}, "properties": {"id": "truck"}}}' \
      | http post http://localhost:8001/vehicle x-api-key:test

> {
    "elapsed": "37.5µs",
    "ok": true
}


http get http://localhost:8001/search/within lat==52.25 lon==13.37 radius==1000 \
  x-api-key:test

> {
    "data": [
        {
            "id": "truck",
            "object": {
                "geometry": {
                    "coordinates": [
                        13.37,
                        52.25
                    ],
                    "type": "Point"
                },
                "properties": {
                    "id": "truck"
                },
                "type": "Feature"
            }
        }
    ]
}

Or you use it with httpx/requests:

import httpx

vehicle = {
    "type": "Feature",
    "geometry": {"type": "Point", "coordinates": [13.37, 52.25]},
    "properties": {"id": "truck"},
}

# store a vehicle
r = httpx.post(
      url="http://localhost:8001/vehicle",
      headers={"x-api-key":"test"},
      json={"data": vehicle}
      )

print(r.json())

> {
    "elapsed": "70.8µs",
    "ok": true
}

# get vehicle in a radius around a location
r = httpx.get(
      url="http://localhost:8001/search/within",
      headers={"x-api-key":"test"},
      params={"lat":52.25,"lon":13.37,"radius":1000}
      )

print(r.json())

> {
    "data": [
        {
            "id": "truck",
            "object": {
                "geometry": {
                    "coordinates": [
                        13.37,
                        52.25
                    ],
                    "type": "Point"
                },
                "properties": {
                    "id": "truck"
                },
                "type": "Feature"
            }
        }
    ]
}

You get the idea. And can use the rest.

Inputs are being validated at runtime with pydantic.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Benjamin Ramser - @imwithpanda - [email protected]
Project Link: https://github.com/iwpnd/fastapi-tile38