This supports a REST interface to the LibPostal API
355
A fault-tolerant REST interface for libpostal using Python, FastAPI, and pypostal.
| Method | Endpoint | Description |
|---|---|---|
| GET | / | API information |
| GET | /health | Health check |
| POST | /parse | Parse single address |
| GET | /parse | Parse single address (query params) |
| POST | /parse_bulk | Parse multiple addresses |
| POST | /expand | Expand single address |
| GET | /expand | Expand single address (query params) |
| POST | /expand_bulk | Expand multiple addresses |
docker build -t libpostal-api .
docker run -p 8000:8000 libpostal-api
Requires libpostal to be installed on the system first. See libpostal installation.
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 8000
# POST
curl -X POST http://localhost:8000/parse \
-H "Content-Type: application/json" \
-d '{"address": "123 Main St, New York, NY 10001"}'
# GET
curl "http://localhost:8000/parse?address=123%20Main%20St%2C%20New%20York%2C%20NY%2010001"
Response:
{
"input": "123 Main St, New York, NY 10001",
"components": [
{"label": "house_number", "value": "123"},
{"label": "road", "value": "main st"},
{"label": "city", "value": "new york"},
{"label": "state", "value": "ny"},
{"label": "postcode", "value": "10001"}
]
}
curl -X POST http://localhost:8000/parse_bulk \
-H "Content-Type: application/json" \
-d '{
"addresses": [
"123 Main St, New York, NY 10001",
"456 Oak Ave, Los Angeles, CA 90001",
"789 Pine Rd, Chicago, IL 60601"
]
}'
Response:
{
"results": [
{
"input": "123 Main St, New York, NY 10001",
"components": [...]
},
{
"input": "456 Oak Ave, Los Angeles, CA 90001",
"components": [...]
},
{
"input": "789 Pine Rd, Chicago, IL 60601",
"components": [...]
}
],
"total": 3,
"errors": []
}
curl -X POST http://localhost:8000/expand \
-H "Content-Type: application/json" \
-d '{"address": "123 Main St Apt 4"}'
Response:
{
"input": "123 Main St Apt 4",
"expansions": [
"123 main street apartment 4",
"123 main street apt 4"
]
}
curl -X POST http://localhost:8000/expand_bulk \
-H "Content-Type: application/json" \
-d '{
"addresses": [
"123 Main St",
"456 Oak Ave"
]
}'
curl http://localhost:8000/health
Response:
{
"status": "healthy",
"libpostal_parser": true,
"libpostal_expand": true
}
Interactive API documentation is available at:
http://localhost:8000/docshttp://localhost:8000/redocThe API returns appropriate HTTP status codes:
200: Success400: Bad request (e.g., empty address)500: Internal server error503: Service unavailable (libpostal not initialized)Bulk endpoints collect errors per-address and return them in the errors array while still processing valid addresses.
Environment variables:
HOST: Server host (default: 0.0.0.0)PORT: Server port (default: 8000)LOG_LEVEL: Logging level (default: info)Content type
Image
Digest
sha256:dc7e924dd…
Size
1 GB
Last updated
8 months ago
docker pull kevintboyle/libpostal-api