Skip to content

Added litestar API endpoints - #36

Merged
kshitijrajsharma merged 7 commits into
osgeonepal:masterfrom
NirrWorks:api/litestar-endpoints
May 6, 2026
Merged

Added litestar API endpoints#36
kshitijrajsharma merged 7 commits into
osgeonepal:masterfrom
NirrWorks:api/litestar-endpoints

Conversation

@NirrWorks

Copy link
Copy Markdown
Contributor

Summary

Adds an initial Litestar API inside the osmsg/api package.

This includes two active endpoints for now:

  • GET /health
  • GET /api/v1/users

The API uses asyncpg to query PostgreSQL and reads the database connection from the DATABASE_URL environment variable.

Changes

  • Added osmsg/api/ package with Litestar app, DB pool setup, and users query.
  • Added /health endpoint for API health checks.
  • Added /api/v1/users endpoint to return ranked user statistics from the current osmsg PostgreSQL tables.
  • Kept future stats endpoints commented out for now.
  • Added Procfile for deployment.
  • Added API dependencies: litestar[standard], asyncpg, and uv.
  • Added route tests for the active API endpoints.

Notes

The API currently expects osmsg data to already be exported into PostgreSQL using the current osmsg schema:

  • users
  • changesets
  • changeset_stats
  • state

Example local run:

uv run litestar --app osmsg.api.app:app run --host 0.0.0.0 --port 8000

Comment thread osmsg/api/app.py Outdated
Comment thread tests/test_api.py
Comment thread pyproject.toml Outdated

@kshitijrajsharma kshitijrajsharma left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the slim PR , beautiful work !
few points ;
add .env example !
add instructions to quickly test the api and the readme , to insert the data and get the api up , usually should be two commands ! expand test cases for real test assertion

@NirrWorks

Copy link
Copy Markdown
Contributor Author

Updated. I added:

  • .env.example with DATABASE_URL
  • README instructions for inserting data into Postgres and starting the API
  • two-command quick test flow:
    • uv run osmsg --last day --format psql --psql-dsn "$DATABASE_URL" --name api_last_day
    • uv run --group api litestar --app osmsg.api.app:app run --host 0.0.0.0 --port 8000
  • expanded API tests with real TestClient requests and expected JSON response assertions

@NirrWorks

Copy link
Copy Markdown
Contributor Author

The API is now hosted on Render and connected to a Neon Postgres database.

Health endpoint:
https://osmsg-1.onrender.com/health

User stats endpoint:
https://osmsg-1.onrender.com/api/v1/user-stats?start=2026-05-02T00:00:00Z&end=2026-05-03T00:00:00Z&limit=10

The database was populated using:
uv run osmsg --last day --summary --format psql --psql-dsn "$DATABASE_URL" --name api_last_day

Comment thread osmsg/api/app.py Outdated
Comment thread osmsg/api/app.py Outdated
Comment thread osmsg/api/db.py Outdated
Comment thread osmsg/api/queries.py Outdated
Comment thread pyproject.toml Outdated

@kshitijrajsharma kshitijrajsharma left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few minor changes !

@kshitijrajsharma
kshitijrajsharma merged commit a681709 into osgeonepal:master May 6, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Under Review to Done in OSMSG : OSM Foundation Grant 2026 May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants