{{ message }}
Expose StructMeta in Python API - #890
Merged
Merged
Conversation
…ns like asdict/json to handle structs created by StructMeta subclasses
Member
Contributor
Author
|
Yes, that's right! |
Contributor
|
It would be worthwhile to document these changes as well, maybe with some use cases as examples EDIT: @ofek ahah, synchronized comments |
Member
|
I'll review later tonight but at a quick glance I noticed there is no information about how to use the new capabilities. Do you think you could take a crack at writing some very basic docs and then I can expand or touch up as need be? |
Contributor
Author
|
Yeah, good point. No problem, will add something simple! |
Contributor
Author
|
How's this, @ofek? |
ofek
approved these changes
Oct 25, 2025
ofek
left a comment
Member
There was a problem hiding this comment.
Thanks a lot for picking this back up!
This was referenced Oct 25, 2025
Contributor
Author
|
Amazing, glad to see this is finally merged!! Thank you! |
This was referenced Nov 11, 2025
|
which version had this exposed? I'm using 0.19.0 and cannot import it. uv run python
Python 3.12.10 (main, Apr 9 2025, 03:49:38) [Clang 20.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import msgspec
>>> dir(msgspec)
['DecodeError', 'EncodeError', 'Meta', 'MsgspecError', 'NODEFAULT', 'Raw', 'Struct', 'UNSET', 'UnsetType', 'ValidationError', '_Field', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_core', '_json_schema', '_utils', '_version', 'convert', 'defstruct', 'field', 'inspect', 'json', 'msgpack', 'structs', 'to_builtins', 'toml', 'yaml']
>>> msgspec.StructMeta
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'msgspec' has no attribute 'StructMeta' |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Re-opening PR for #843 and #844. Copying @nightsailer's initial PR message below:
Expose and Enable Inheritance of StructMeta Metaclass
Changes
StructMetametaclass to Python for direct usePy_TPFLAGS_BASETYPEflag to enable Python inheritance ofStructMetaWhy
This allows users to:
StructMetadirectly without subclassingStructStructMetabehaviorThis PR resolves:
kw_onlyforStruct(e.g.,kw_only_default=True) #841msgspec.Struct#837Example
Technical Details
Added StructMeta to module exports in _core.c Added Py_TPFLAGS_BASETYPE flag to StructMetaType Updated init.py to import and expose StructMeta Added type hints in init.pyi
Compatibility
These changes are backward compatible and only add new capabilities without modifying existing behavior.
Related Issues