Skip to content

Fastapi conversion#2071

Draft
bfoley12 wants to merge 166 commits into
devfrom
fastapi-conversion
Draft

Fastapi conversion#2071
bfoley12 wants to merge 166 commits into
devfrom
fastapi-conversion

Conversation

@bfoley12

@bfoley12 bfoley12 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Start of major rewrite of the API server to FastAPI and other modern frameworks (pydantic, Beanie, etc.)

This PR is the essential groundwork of the rewrite. However, further PRs are necessary for full functionality.

Major TODOs after this PR

  • Downloads
    • This involves infra design to push data from Contributions and Components into S3 as parquet (maybe delta tables if it goes that far)
  • Unit normalization (Pint/Unyt)
    • Also entails making input data formatted strings, then internally parsing the formats into better representations (objects) before storage
  • Greatly expand telemetry

Minor TODOs after this PR:

  • Add indices to Beanie models
  • Remove notebooks
  • Remove CIF
  • Email notifications

@bfoley12 bfoley12 self-assigned this Jun 16, 2026
@bfoley12 bfoley12 added this to the API Server Rewrite milestone Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removing jupyter and local datadog reference

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removing jupyter and local datadog reference

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ruff formatting

Comment thread mpcontribs-api/gunicorn.conf.py Outdated

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fastapi uses uvicorn

Comment thread mpcontribs-api/justfile

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Convenient command runner

Comment thread mpcontribs-api/Dockerfile

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Switch from pip building to uv.
!! Needs further verification

Comment thread mpcontribs-api/main.py

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ruff formatting

Comment thread mpcontribs-api/maintenance.py Outdated

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not using MongoEngine.
!! Still need to implement unit checks, but will be outside of this scope

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Upgrade python to 3.14; move to uv, ruff, and basedpyright; removed outdated/unnecessary packages

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.

the base stack is still at python 3.11

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I have a note in the Dockerfile about requiring a 3.14 image build - I assumed it would be a good time to bump our python version and use up to date package versions.
Do you think this should be in the scope of the rewrite?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A lot of this logic is used to handle parsing dotted paths (data.x.y.z)

Comment thread mpcontribs-api/Dockerfile
Comment on lines -25 to -26
wget -q https://github.com/materialsproject/MPContribs/blob/master/mpcontribs-api/mpcontribs/api/contributions/formulae.json.gz?raw=true \
-O mpcontribs/api/contributions/formulae.json.gz

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.

reason for removing the formulae file?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The file seemed to just function as an id-to-formula translation. I made formulas required when POSTing.

If we want that moved back to optional and filled in automatically, I think I'd prefer actively fetching the formula over keeping it in a data file that we track in git. That would mean an extra query to mongo, and reaching into the nextgen database, but I feel that it is more reactive and resilient that way.

…across our stack easily, but loses centralization. We only had light centralization, but future efforts would not be immediately shared
Comment thread mpcontribs-api/Dockerfile
FROM materialsproject/devops:python-3.1113.4 AS base
RUN apt-get update && apt-get install -y --no-install-recommends supervisor libopenblas-dev libpq-dev vim && apt-get clean
# FROM materialsproject/devops:python-3.1113.4 AS base
FROM python:3.14-slim AS base

@bfoley12 bfoley12 Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I moved off of the shared base image here. There are definitely both pros and cons (below), and I have to test a full build still.
Pros:

  1. UV uses a lockfile and doesn't need to rely on manually finding and building binaries - this seems to be the main benefit of the shared image (scipy, matplotlib, etc.)
  2. Allows each portion of the stack to upgrade python independently (we don't have to hold back one piece until we build a shared image and force every upgrade at once)

Cons:

  1. If we have truly shared logic, we will have duplication, or revert to a shared image
  2. If the underlying default image changes, we would silently change as well

bfoley12 added 24 commits June 18, 2026 10:15
…ser - users can no longer operate on components that their contributions dontown
…from Document instead of DocumentWithSoftDelet
…eporting the successes and failures via BulkWriteSummary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants