No description
  • Python 96.2%
  • Dockerfile 3.8%
Find a file
Aareon Sullivan ae6db6ed2c first commit
2024-10-27 22:24:48 -05:00
geonames_fastapi first commit 2024-10-27 22:24:48 -05:00
.gitignore first commit 2024-10-27 22:24:48 -05:00
Dockerfile first commit 2024-10-27 22:24:48 -05:00
poetry.lock first commit 2024-10-27 22:24:48 -05:00
pyproject.toml first commit 2024-10-27 22:24:48 -05:00
README.md first commit 2024-10-27 22:24:48 -05:00
run.py first commit 2024-10-27 22:24:48 -05:00
setup.py first commit 2024-10-27 22:24:48 -05:00

GeoNames FastAPI

A FastAPI wrapper for the python-geonames library, providing RESTful API access to GeoNames data.

Features

  • Async API endpoints for GeoNames data
  • Full OpenAPI documentation
  • Input validation using Pydantic
  • Easy deployment with Docker
  • Comprehensive test coverage

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/geonames-fastapi.git
cd geonames-fastapi
  1. Install dependencies with Poetry:
poetry install
  1. Create data directory:
mkdir geonames_data

Development

  1. Activate the virtual environment:
poetry shell
  1. Run the development server:
uvicorn app.main:app --reload

The API will be available at http://localhost:8000. API documentation is available at:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Testing

Run tests with pytest:

pytest

Run tests with coverage:

pytest --cov=app tests/

API Endpoints

  • GET /health - Health check endpoint
  • GET /stats - Get database statistics
  • GET /location/{country_code}/{postal_code} - Get location by country code and postal code
  • GET /search/name/{name} - Search locations by name
  • GET /search/coordinates?lat={lat}&lon={lon}&radius={radius} - Search locations by coordinates
  • GET /search/country/{country_code} - Search locations by country code

Docker Deployment

  1. Build the Docker image:
docker build -t geonames-fastapi .
  1. Run the container:
docker run -d -p 8000:8000 geonames-fastapi

Project Structure

geonames-fastapi/
├── app/
│   ├── __init__.py
│   ├── main.py
│   ├── models.py
│   └── dependencies.py
├── tests/
│   ├── __init__.py
│   ├── conftest.py
│   └── test_api.py
├── geonames_data/
├── Dockerfile
├── pyproject.toml
├── README.md
└── .gitignore

License

MIT License