Town / City geolocations with FastAPI & Mongo

Overview

Makefile CI

geolocations-api

United Kingdom Town / City geolocations with FastAPI & Mongo

Build container

To build a custom image or extend the api run the following cmds

# update the following variables as required
API_PORT=7000
API_HOST=locahost
# API variables
API_DB_NAME=towns_db
API_DB_USERNAME=admin
API_DB_PASSWORD=admin
API_DB_HOST=host.docker.internal
API_DB_PORT=27017

# Then build & run
make docker-build
make docker-run

Build locally instructions

Open Makefile in your ide & update the following varables as required:

DB_NAME=<YOUR_DB_NAME>
DB_USERNAME=<YOUR_DB_USERNAME>
DB_PASSWORD=<YOUR_DB_PASSWORD>

Make sure you have mongoimport command available & run the below command to import the towns JSON dump

make mongo-import-towns
You might also like...
Adds simple SQLAlchemy support to FastAPI

FastAPI-SQLAlchemy FastAPI-SQLAlchemy provides a simple integration between FastAPI and SQLAlchemy in your application. It gives access to useful help

Opinionated set of utilities on top of FastAPI

FastAPI Contrib Opinionated set of utilities on top of FastAPI Free software: MIT license Documentation: https://fastapi-contrib.readthedocs.io. Featu

Reusable utilities for FastAPI

Reusable utilities for FastAPI Documentation: https://fastapi-utils.davidmontague.xyz Source Code: https://github.com/dmontagu/fastapi-utils FastAPI i

This code generator creates FastAPI app from an openapi file.

fastapi-code-generator This code generator creates FastAPI app from an openapi file. This project is an experimental phase. fastapi-code-generator use

FastAPI framework plugins

Plugins for FastAPI framework, high performance, easy to learn, fast to code, ready for production fastapi-plugins FastAPI framework plugins Cache Mem

Prometheus exporter for Starlette and FastAPI

starlette_exporter Prometheus exporter for Starlette and FastAPI. The middleware collects basic metrics: Counter: starlette_requests_total Histogram:

🚀   Cookiecutter Template for FastAPI + React Projects.  Using PostgreSQL, SQLAlchemy, and Docker
🚀 Cookiecutter Template for FastAPI + React Projects. Using PostgreSQL, SQLAlchemy, and Docker

FastAPI + React · A cookiecutter template for bootstrapping a FastAPI and React project using a modern stack. Features FastAPI (Python 3.8) JWT authen

A rate limiter for Starlette and FastAPI

SlowApi A rate limiting library for Starlette and FastAPI adapted from flask-limiter. Note: this is alpha quality code still, the API may change, and

api versioning for fastapi web applications

fastapi-versioning api versioning for fastapi web applications Installation pip install fastapi-versioning Examples from fastapi import FastAPI from f

Comments
  • Error calling make mongo-import-towns

    Error calling make mongo-import-towns

    logs:

    [email protected]:~/Projects/geolocations-api$ make mongo-import-towns
    mongoimport -d bn_database -c towns --file ./towns.json --authenticationDatabase admin --username admin --password admin --host localhost --port 27017
    2022-01-11T11:34:12.832+0000	Failed: error connecting to db server: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field.
    2022-01-11T11:34:12.832+0000	imported 0 documents
    make: *** [Makefile:30: mongo-import-towns] Error 1
    
    
    bug 
    opened by joegasewicz 1
  • Running on Linux

    Running on Linux

    Error running on Ubuntu 20.04.3 LTS

    geolocations_1  | ERROR:    Exception in ASGI application
    geolocations_1  | Traceback (most recent call last):
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 376, in run_asgi
    geolocations_1  |     result = await app(self.scope, self.receive, self.send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    geolocations_1  |     return await self.app(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/fastapi/applications.py", line 208, in __call__
    geolocations_1  |     await super().__call__(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/applications.py", line 112, in __call__
    geolocations_1  |     await self.middleware_stack(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/middleware/errors.py", line 181, in __call__
    geolocations_1  |     raise exc
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/middleware/errors.py", line 159, in __call__
    geolocations_1  |     await self.app(scope, receive, _send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/middleware/cors.py", line 84, in __call__
    geolocations_1  |     await self.app(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/exceptions.py", line 82, in __call__
    geolocations_1  |     raise exc
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/exceptions.py", line 71, in __call__
    geolocations_1  |     await self.app(scope, receive, sender)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/routing.py", line 656, in __call__
    geolocations_1  |     await route.handle(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/routing.py", line 259, in handle
    geolocations_1  |     await self.app(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/routing.py", line 61, in app
    geolocations_1  |     response = await func(request)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/fastapi/routing.py", line 226, in app
    geolocations_1  |     raw_response = await run_endpoint_function(
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/fastapi/routing.py", line 161, in run_endpoint_function
    geolocations_1  |     return await run_in_threadpool(dependant.call, **values)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/concurrency.py", line 39, in run_in_threadpool
    geolocations_1  |     return await anyio.to_thread.run_sync(func, *args)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/anyio/to_thread.py", line 28, in run_sync
    geolocations_1  |     return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 818, in run_sync_in_worker_thread
    geolocations_1  |     return await future
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 754, in run
    geolocations_1  |     result = context.run(func, *args)
    geolocations_1  |   File "/geolocations-api/./api/main.py", line 65, in locations
    geolocations_1  |     serialized_towns = mongo_id.multiple(towns)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/mongo_id_marshaller/mongo_id.py", line 31, in multiple
    geolocations_1  |     for query_data in _doc_generator(query_list):
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/mongo_id_marshaller/mongo_id.py", line 5, in _doc_generator
    geolocations_1  |     for doc in mongo_docs:
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/cursor.py", line 1159, in next
    geolocations_1  |     if len(self.__data) or self._refresh():
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/cursor.py", line 1057, in _refresh
    geolocations_1  |     self.__session = self.__collection.database.client._ensure_session()
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1603, in _ensure_session
    geolocations_1  |     return self.__start_session(True, causal_consistency=False)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1553, in __start_session
    geolocations_1  |     server_session = self._get_server_session()
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1589, in _get_server_session
    geolocations_1  |     return self._topology.get_server_session()
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/topology.py", line 530, in get_server_session
    geolocations_1  |     session_timeout = self._check_session_support()
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/topology.py", line 514, in _check_session_support
    geolocations_1  |     self._select_servers_loop(
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/topology.py", line 216, in _select_servers_loop
    geolocations_1  |     raise ServerSelectionTimeoutError(
    geolocations_1  | pymongo.errors.ServerSelectionTimeoutError: host.docker.internal:27017: [Errno -2] Name or service not known, Timeout: 30s, Topology Description: <TopologyDescription id: 61dd85923abcec01d811f834, topology_type: Unknown, servers: [<ServerDescription ('host.docker.internal', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('host.docker.internal:27017: [Errno -2] Name or service not known')>]>
    geolocations_1  | ERROR:    Exception in ASGI application
    geolocations_1  | Traceback (most recent call last):
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 376, in run_asgi
    geolocations_1  |     result = await app(self.scope, self.receive, self.send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    geolocations_1  |     return await self.app(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/fastapi/applications.py", line 208, in __call__
    geolocations_1  |     await super().__call__(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/applications.py", line 112, in __call__
    geolocations_1  |     await self.middleware_stack(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/middleware/errors.py", line 181, in __call__
    geolocations_1  |     raise exc
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/middleware/errors.py", line 159, in __call__
    geolocations_1  |     await self.app(scope, receive, _send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/middleware/cors.py", line 84, in __call__
    geolocations_1  |     await self.app(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/exceptions.py", line 82, in __call__
    geolocations_1  |     raise exc
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/exceptions.py", line 71, in __call__
    geolocations_1  |     await self.app(scope, receive, sender)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/routing.py", line 656, in __call__
    geolocations_1  |     await route.handle(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/routing.py", line 259, in handle
    geolocations_1  |     await self.app(scope, receive, send)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/routing.py", line 61, in app
    geolocations_1  |     response = await func(request)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/fastapi/routing.py", line 226, in app
    geolocations_1  |     raw_response = await run_endpoint_function(
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/fastapi/routing.py", line 161, in run_endpoint_function
    geolocations_1  |     return await run_in_threadpool(dependant.call, **values)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/starlette/concurrency.py", line 39, in run_in_threadpool
    geolocations_1  |     return await anyio.to_thread.run_sync(func, *args)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/anyio/to_thread.py", line 28, in run_sync
    geolocations_1  |     return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 818, in run_sync_in_worker_thread
    geolocations_1  |     return await future
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 754, in run
    geolocations_1  |     result = context.run(func, *args)
    geolocations_1  |   File "/geolocations-api/./api/main.py", line 65, in locations
    geolocations_1  |     serialized_towns = mongo_id.multiple(towns)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/mongo_id_marshaller/mongo_id.py", line 31, in multiple
    geolocations_1  |     for query_data in _doc_generator(query_list):
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/mongo_id_marshaller/mongo_id.py", line 5, in _doc_generator
    geolocations_1  |     for doc in mongo_docs:
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/cursor.py", line 1159, in next
    geolocations_1  |     if len(self.__data) or self._refresh():
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/cursor.py", line 1057, in _refresh
    geolocations_1  |     self.__session = self.__collection.database.client._ensure_session()
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1603, in _ensure_session
    geolocations_1  |     return self.__start_session(True, causal_consistency=False)
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1553, in __start_session
    geolocations_1  |     server_session = self._get_server_session()
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1589, in _get_server_session
    geolocations_1  |     return self._topology.get_server_session()
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/topology.py", line 530, in get_server_session
    geolocations_1  |     session_timeout = self._check_session_support()
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/topology.py", line 514, in _check_session_support
    geolocations_1  |     self._select_servers_loop(
    geolocations_1  |   File "/root/.local/share/virtualenvs/geolocations-api-NPGMF1o2/lib/python3.10/site-packages/pymongo/topology.py", line 216, in _select_servers_loop
    geolocations_1  |     raise ServerSelectionTimeoutError(
    geolocations_1  | pymongo.errors.ServerSelectionTimeoutError: host.docker.internal:27017: [Errno -2] Name or service not known, Timeout: 30s, Topology Description: <TopologyDescription id: 61dd85923abcec01d811f834, topology_type: Unknown, servers: [<ServerDescription ('host.docker.internal', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('host.docker.internal:27017: [Errno -2] Name or service not known')>]>
    
    
    bug 
    opened by joegasewicz 0
Releases(v1.0.0)
Owner
Joe Gasewicz
I'm a Go, Python, Typescript, Swift & C full stack developer.. I'm a Jazz bassist & prefer cats.
Joe Gasewicz
A utility that allows you to use DI in fastapi without Depends()

fastapi-better-di What is this ? fastapi-better-di is a utility that allows you to use DI in fastapi without Depends() Installation pip install fastap

Maxim 9 May 24, 2022
Sample project showing reliable data ingestion application using FastAPI and dramatiq

Create and deploy a reliable data ingestion service with FastAPI, SQLModel and Dramatiq This is the source code for the data ingestion service explain

François Voron 31 Nov 30, 2022
Prometheus exporter for metrics from the MyAudi API

Prometheus Audi Exporter This Prometheus exporter exports metrics that it fetches from the MyAudi API. Usage Checkout submodules Install dependencies

Dieter Maes 7 Dec 19, 2022
Flask + marshmallow for beautiful APIs

Flask-Marshmallow Flask + marshmallow for beautiful APIs Flask-Marshmallow is a thin integration layer for Flask (a Python web framework) and marshmal

marshmallow-code 768 Dec 22, 2022
A FastAPI Plug-In to support authentication authorization using the Microsoft Authentication Library (MSAL)

FastAPI/MSAL - MSAL (Microsoft Authentication Library) plugin for FastAPI FastAPI - https://github.com/tiangolo/fastapi FastAPI is a modern, fast (hig

Dudi Levy 15 Jul 20, 2022
🐞 A debug toolbar for FastAPI based on the original django-debug-toolbar. 🐞

Debug Toolbar 🐞 A debug toolbar for FastAPI based on the original django-debug-toolbar. 🐞 Swagger UI & GraphQL are supported. Documentation: https:/

Dani 74 Dec 30, 2022
Town / City geolocations with FastAPI & Mongo

geolocations-api United Kingdom Town / City geolocations with FastAPI & Mongo Build container To build a custom image or extend the api run the follow

Joe Gasewicz 3 Jan 26, 2022
Twitter API monitor with fastAPI + MongoDB

Twitter API monitor with fastAPI + MongoDB You need to have a file .env with the following variables: DB_URL="mongodb+srv://mongodb_path" DB_URL2=

Leonardo Ferreira 3 Apr 08, 2022
FastAPI-Amis-Admin is a high-performance, efficient and easily extensible FastAPI admin framework. Inspired by django-admin, and has as many powerful functions as django-admin.

简体中文 | English 项目介绍 FastAPI-Amis-Admin fastapi-amis-admin是一个拥有高性能,高效率,易拓展的fastapi管理后台框架. 启发自Django-Admin,并且拥有不逊色于Django-Admin的强大功能. 源码 · 在线演示 · 文档 · 文

AmisAdmin 318 Dec 31, 2022
Starlette middleware for Prerender

Prerender Python Starlette Starlette middleware for Prerender Documentation: https://BeeMyDesk.github.io/prerender-python-starlette/ Source Code: http

BeeMyDesk 14 May 02, 2021
Simple web app example serving a PyTorch model using streamlit and FastAPI

streamlit-fastapi-model-serving Simple example of usage of streamlit and FastAPI for ML model serving described on this blogpost and PyConES 2020 vide

Davide Fiocco 291 Jan 06, 2023
:rocket: CLI tool for FastAPI. Generating new FastAPI projects & boilerplates made easy.

Project generator and manager for FastAPI. Source Code: View it on Github Features 🚀 Creates customizable project boilerplate. Creates customizable a

Yagiz Degirmenci 1k Jan 02, 2023
Docker image with Uvicorn managed by Gunicorn for high-performance FastAPI web applications in Python 3.6 and above with performance auto-tuning. Optionally with Alpine Linux.

Supported tags and respective Dockerfile links python3.8, latest (Dockerfile) python3.7, (Dockerfile) python3.6 (Dockerfile) python3.8-slim (Dockerfil

Sebastián Ramírez 2.1k Dec 31, 2022
Turns your Python functions into microservices with web API, interactive GUI, and more.

Instantly turn your Python functions into production-ready microservices. Deploy and access your services via HTTP API or interactive UI. Seamlessly export your services into portable, shareable, and

Machine Learning Tooling 2.8k Jan 04, 2023
FastAPI application and service structure for a more maintainable codebase

Abstracting FastAPI Services See this article for more information: https://camillovisini.com/article/abstracting-fastapi-services/ Poetry poetry inst

Camillo Visini 309 Jan 04, 2023
Cookiecutter API for creating Custom Skills for Azure Search using Python and Docker

cookiecutter-spacy-fastapi Python cookiecutter API for quick deployments of spaCy models with FastAPI Azure Search The API interface is compatible wit

Microsoft 379 Jan 03, 2023
A dynamic FastAPI router that automatically creates CRUD routes for your models

⚡ Create CRUD routes with lighting speed ⚡ A dynamic FastAPI router that automatically creates CRUD routes for your models Documentation: https://fast

Adam Watkins 943 Jan 01, 2023
Sample FastAPI project that uses async SQLAlchemy, SQLModel, Postgres, Alembic, and Docker.

FastAPI + SQLModel + Alembic Sample FastAPI project that uses async SQLAlchemy, SQLModel, Postgres, Alembic, and Docker. Want to learn how to build th

228 Jan 02, 2023
🔀⏳ Easy throttling with asyncio support

Throttler Zero-dependency Python package for easy throttling with asyncio support. 📝 Table of Contents 🎒 Install 🛠 Usage Examples Throttler and Thr

Ramzan Bekbulatov 80 Dec 07, 2022
Code for my FastAPI tutorial

FastAPI tutorial Code for my video tutorial FastAPI tutorial What is FastAPI? FastAPI is a high-performant REST API framework for Python. It's built o

José Haro Peralta 9 Nov 15, 2022