Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Readme
pymarshal replicates the feature of (un)marshalling structs in Golang. Rather than replicating the exact feature as it exists in Go, pymarshal aims for elegant, Pythonic simplicity, and to fix the flaws in Go's implementation such as:
Support for the following has been removed:
If you need any of these, use 1.6.2
As YAML is compatible with JSON, use PyYAML to load or dump data
with the pymarshal.json
module, there is no explicit YAML module.
It is recommended that you install
from PyPI
using pip install pymarshal
The only modification required to your class code is to use the type_assert
functions to assign __init__
arguments to class fields of the same
name. pymarshal provides the type_assert
functions to both enforce the type,
and to unmarshal nested objects.
Example:
class MyModel:
def __init__(
self,
a,
b=5,
):
self.a = type_assert(a, str)
self.b = type_assert(b, int)
>>> from pymarshal.json import *
>>> x = marshal_json(MyModel("test", 6))
>>> x
{"a": "test", "b": 6}
>>> y = unmarshal_json(x, MyModel)
>>> y.a
"test"
NOTE: Your classes must not implement __call__
(which is an antipattern
anyway). Whatever you would've implemented with __call__
should just be
a normal, named method.
Your __init__
methods should only use simple assignment through the
type_assert
functions. If you have a use-case for a constructor that
does more than simple assignment, use a separate
'factory' static method.
There is also:
type_assert_iter
for iterablestype_assert_dict
for anything that implements .items() -> k, vRather than using the Golang "tag" syntax, simply create a
_marshal_key_swap
and _unmarshal_key_swap
dict in your class,
and any re-named keys will be swapped before being passed to the
class constructor or before being marshalled to JSON. The full list
of control variables are documented HERE.
FAQs
Pythonic implementation of Golang struct (un)marshalling
We found that pymarshal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.