Skip to content

Mpc api#32

Open
matthewjohnpayne wants to merge 16 commits intomainfrom
mpc-api
Open

Mpc api#32
matthewjohnpayne wants to merge 16 commits intomainfrom
mpc-api

Conversation

@matthewjohnpayne
Copy link
Collaborator

@matthewjohnpayne matthewjohnpayne commented Feb 14, 2026

Introduces an mpc_api package that is intended to be a pip-installable package on PyPi.
mpc_api provides a single MPCClient class with methods for all 10 MPC public APIs:

  • identify,
  • get_orbit,
  • get_observations,
  • get_observatory,
  • get_mpecs,
  • check_near_duplicates,
  • get_submission_status,
  • submit_xml/psv,
  • request_action_code, and
  • get_neocp_observations.

Includes optional pandas DataFrame output, custom exception hierarchy, and 60 mocked tests.

This PR also

  • updates all api tutorial notebooks with mpc_api usage examples
  • adds a Getting Started notebook for the mpc_api package

I have verified that the code works and that the main demo notebook, mpc_tutorial_mpcapi.ipynb, also works and provides simple-but-cogent explanations of the individual apis, as well as linking out to the tutorials & documentation for the APIs.

NB:

  • As per my comment in PR31 , It's probably reasonably obvious that I created this using claude-code.
  • It's unclear to me how we should be reviewing such code going forward: It works, but it was all produced in a few hours, and reviewers will have a hard time digesting such a large volume of code.

matthewjohnpayne and others added 4 commits February 14, 2026 15:12
Introduces MPCClient class with methods for all 10 MPC public APIs:
identify, get_orbit, get_observations, get_observatory, get_mpecs,
check_near_duplicates, get_submission_status, submit_xml/psv,
request_action_code, and get_neocp_observations. Includes optional
pandas DataFrame output, custom exception hierarchy, and 60 mocked
tests. Updates all tutorial notebooks with mpc_api usage examples
and adds a Getting Started notebook.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Each notebook opening markdown cell now mentions the mpc_api
package as an alternative, with a link to the detailed examples
lower in the same notebook.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@matthewjohnpayne
Copy link
Collaborator Author

@federicaspoto : I've asked @fiftymillionfeltcapfanscantbewrong to review this PR, but I'm just flagging you on it so that you are aware of it (e.g. for newsletter/similar).

Comment on lines 36 to 49
def test_get_neocp_observations_df(client):
responses.get(
NEOCP_URL,
json=[{
"ADES_DF": [
{"trksub": "P21Eetc", "obstime": "2025-02-10", "ra": 10.0, "dec": 20.0, "stn": "F51"},
{"trksub": "P21Eetc", "obstime": "2025-02-11", "ra": 11.0, "dec": 21.0, "stn": "G96"},
]
}],
)

df = client.get_neocp_observations_df("P21Eetc")
assert isinstance(df, pd.DataFrame)
assert len(df) == 2
Copy link
Member

@federicaspoto federicaspoto Feb 18, 2026

Choose a reason for hiding this comment

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

I haven't tested this, but in principle this should not work unless the tracklet is currently on the NEOCP. This doesn't seem to be the expected behavior though.

Copy link
Collaborator Author

@matthewjohnpayne matthewjohnpayne Feb 28, 2026

Choose a reason for hiding this comment

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

I'm not quite sure what you mean here, but I suspect it is lack of clarify in the tests regarding what @responses.activate does (it mocks API responses).

As such, I have added more tests, and then split the tests into 3 main sections:

  1. tests that actually, for real, call the API (but are allowed to fail/skip if the API is unavailable)
  • N.B. I'm allowing these to pass if the API is unavailable because it is not strictly the job of mpc_api to be the api, and also, I don't want the CI to get screwed-up due to (e.g.) downtime in mpcweb6
  1. tests that mock the API response, so that we are purely testing this mpc_api.MPCClient
  2. tests that are independent of the API (such as error handling within mpc_api)

I note that I have done the same for all of the various test files in tests/test_*.py, and added a bunch of comments to make clear what is going on.

matthewjohnpayne and others added 10 commits February 28, 2026 13:35
…d tutorial notebook

- Rename mpc_api/ to mpc-api/ and move source to src/ layout for packaging
- Update pyproject.toml hatch build targets, add lxml to test deps
- Update GitHub Actions workflows for new paths
- Add real API tests to all test files with per-endpoint skip logic
- Add shared check_api fixture in conftest.py for graceful API-unavailable skipping
- Add updated mpc_tutorial_mpcapi.ipynb notebook with install cell and all API demos

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Publishes to TestPyPI on every PR that touches mpc-api/, with a
unique .devN version suffix per run. Also supports manual dispatch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update release workflow to trigger on push to main (in addition to
manual releases). Checks PyPI for the current version and skips
publish if it already exists, so only version bumps cause a release.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@matthewjohnpayne
Copy link
Collaborator Author

matthewjohnpayne commented Feb 28, 2026

OK, @federicaspoto , @fiftymillionfeltcapfanscantbewrong , I have addressed the previous comments regarding mpc_api.

I have also verified that the version currently released to TestPyPI works when downloaded.

I have clarified the README

I have also added various .github/workflows/ to ensure that

  1. the code will be released to TestPyPI on every push to a PR involving mpc_api, and
  2. the code will be released to PyPI on every merge to main of a PR involving mpc_api.

matthewjohnpayne and others added 2 commits February 28, 2026 14:31
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