Skip to content

Standard APIs for PEP 751? #898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
woodruffw opened this issue May 5, 2025 · 6 comments · May be fixed by #900
Open

Standard APIs for PEP 751? #898

woodruffw opened this issue May 5, 2025 · 6 comments · May be fixed by #900

Comments

@woodruffw
Copy link
Member

woodruffw commented May 5, 2025

Hey all!

I'm opening this for discussion/to gauge interest.

TL;DR: I think it would be nice to have an "official" API for PEP 751 in packaging. This would ease/accelerate the adoption curve for Python packaging tooling that already uses packaging, since they could import existing APIs that are consistent across the entire ecosystem rather than doing their own at-hoc/at-point deserialization/modeling.

Some related thoughts:

I'm curious what people think about this! CCing @brettcannon and @pradyunsg and @sbidoul in particular since I know you've all been involved in PEP 751 and its adoption 🙂

+CC @di @sethmlarson as other interested parties 🙂

@di
Copy link
Member

di commented May 5, 2025

Agreed! Not sure if this issue is a coincidence but @sbidoul just asked about this very thing here.

I think APIs for creating & reading pylock files would probably make sense to included here and the model currently in pip seems like a good starting point.

@woodruffw
Copy link
Member Author

Agreed! Not sure if this issue is a coincidence but @sbidoul just asked about this very thing here.

I completely missed that! Apologies to @sbidoul, looks like you're way ahead of what I was thinking in terms of APIs.

@sbidoul
Copy link
Member

sbidoul commented May 5, 2025

models/pylock.py in pypa/pip#13369 is indeed a more advanced starting point.

  • the models are complete
  • the dataclasses are immutable and kw_only
  • they are fully typed
  • it has to_dict and from_dict compatible with the toml serialization
  • from_dict validation is fairly extensive
  • I purposely left out writing toml as the exact serialization format is more complex and there are decisions to be made about which tables to inline, etc. But that can eventually be added later.

If packaging maintainers think that approach is on the right track, I can open a PR here for review.

@brettcannon
Copy link
Member

I personally assumed that we would end up with something like packaging.metadata; basically a TypedDict when the TOML is parsed and then a more structured one that build off the dict. But I'm also happy with skipping straight to the structured output like what @sbidoul has in pip since it's not exactly controversial as it closely mirrors the TOML structure and we shouldn't have messy data out there to need raw data access for.

@brettcannon
Copy link
Member

One thing to keep in mind is future changes to the spec, both minor changes and new versions. That probably means versioning things.

@sbidoul sbidoul linked a pull request May 6, 2025 that will close this issue
@sbidoul
Copy link
Member

sbidoul commented May 6, 2025

I created #900.

One thing to keep in mind is future changes to the spec, both minor changes and new versions. That probably means versioning things.

Good point. I made from_dict a function instead of a class method so it can eventually instantiate different classes depending on the version discovered.

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 a pull request may close this issue.

4 participants