Skip to content

A FastAPI-based microservice for object detection tasks with asynchronous processing.

porameht/object-detection-api

Repository files navigation

Object Detection API

FastAPI service to submit images for object detection and check task status.

Screenshot 2568-08-23 at 16 03 28

Quick Start

  • Prerequisites: Python 3.8+, Redis, Google Cloud project (Storage + Pub/Sub enabled)
  • Install:
pip install -r requirements.txt
  • Configure env (example):
export REDIS_URL=redis://localhost:6379
export GCP_PROJECT_ID=your-gcp-project
export GCS_BUCKET=object-detection-images
export PUBSUB_TOPIC=object-detection-tasks
export TASK_TTL=3600
  • Run:
python -m uvicorn src.main:app --host 0.0.0.0 --port 8000

Open http://localhost:8000/docs

Endpoints

  • POST /detect: submit an image (multipart field image)
curl -X POST http://localhost:8000/detect \
  -F "image=@/path/to/image.jpg"
  • GET /status/{task_id}: check task status and results
curl http://localhost:8000/status/<uuid>
  • GET /health: lightweight health (add ?deep=1 for a light GCS probe)
  • POST /internal/task-completed: worker callback, returns 204

Environment Variables

  • REDIS_URL: Redis connection URL
  • GCP_PROJECT_ID: GCP project id
  • GCS_BUCKET: GCS bucket for images
  • PUBSUB_TOPIC: Pub/Sub topic for tasks
  • TASK_TTL: Task TTL in seconds (default 3600)

Project Layout

  • src/domain: entities, enums
  • src/application: use cases, schemas
  • src/infrastructure: providers, Redis/GCS/PubSub
  • src/main.py: FastAPI app & routes

Notes

  • Detection runs in a separate worker; this API enqueues and tracks tasks
  • Blocking SDK calls are wrapped with anyio.to_thread.run_sync to keep the event loop responsive

About

A FastAPI-based microservice for object detection tasks with asynchronous processing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages