Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hgromer committed Nov 8, 2020
1 parent fef070c commit 04c879c
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 36 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Pymarshal - Marshal and Unmarshal Python Objects
# Pymarshaler - Marshal and Unmarshal Python Objects

## About
Pymarshal allows you to marshal and unmarshal any python object directly to and from a JSON formatted string.
Pymarshaler allows you to marshal and unmarshal any python object directly to and from a JSON formatted string.

Pymarshal takes advantage of python's new [typing support](https://docs.python.org/3/library/typing.html). By reading class init param types, we are able to walk down nested JSON structures and assign appropriate values.
Pymarshaler takes advantage of python's new [typing support](https://docs.python.org/3/library/typing.html). By reading class init param types, we are able to walk down nested JSON structures and assign appropriate values.

## Basic Usage

Expand All @@ -19,7 +19,7 @@ class Test:
That's it! We can now marshal, and more importantly, unmarshal this object to and from JSON.

```python
from pymarshal import marshal
from pymarshaler import marshal
import json

test_instance = Test('foo')
Expand Down Expand Up @@ -54,11 +54,11 @@ print(result.test.name)

As you can see, adding a nested class is as simple as as adding a basic structure.

Pymarshal will fail when encountering an unknown field by default, however you can configure it to ignore unknown fields
Pymarshaler will fail when encountering an unknown field by default, however you can configure it to ignore unknown fields

```python
from pymarshal import marshal
from pymarshal.arg_delegates import ArgBuilderFactory
from pymarshaler import marshal
from pymarshaler.arg_delegates import ArgBuilderFactory

blob = {'test': 'foo', 'unused_field': 'blah'}
result = marshal.unmarshal(Test, blob)
Expand All @@ -72,10 +72,10 @@ print(result.name)

## Advanced Usage

We can use pymarshal to handle containers as well. Again we take advantage of python's robust typing system
We can use pymarshaler to handle containers as well. Again we take advantage of python's robust typing system

```python
from pymarshal import marshal
from pymarshaler import marshal
from typing import Set
import json

Expand All @@ -94,12 +94,12 @@ print(result.container)
>>> '{foo, bar}'
```

Pymarshal can also handle containers that store user defined types. The `Set[str]` could easily have been `Set[UserDefinedType]`
Pymarshaler can also handle containers that store user defined types. The `Set[str]` could easily have been `Set[UserDefinedType]`

Pymarshal also supports default values, and will use any default values supplied in the `__init__` if those values aren't present in the JSON data.
Pymarshaler also supports default values, and will use any default values supplied in the `__init__` if those values aren't present in the JSON data.

```python
from pymarshal import marshal
from pymarshaler import marshal

class TestWithDefault:

Expand All @@ -110,12 +110,12 @@ result = marshal.unmarshal(TestWithDefault, {})
print(result.name)
>>> 'foo'
```
Pymarshal will raise an error if any non-default attributes aren't given
Pymarshaler will raise an error if any non-default attributes aren't given

Pymarshal also supports a validate method on creation of the python object. This method will be called before being returned to the user.
Pymarshaler also supports a validate method on creation of the python object. This method will be called before being returned to the user.

```python
from pymarshal import marshal
from pymarshaler import marshal

class TestWithValidate:

Expand All @@ -135,8 +135,8 @@ This can be used to validate the python object right at construction, potentiall
It's also possible to register your own custom unmarshaler for specific user defined classes.

```python
from pymarshal.arg_delegates import ArgBuilderDelegate, ArgBuilderFactory
from pymarshal import marshal
from pymarshaler.arg_delegates import ArgBuilderDelegate, ArgBuilderFactory
from pymarshaler import marshal


class ClassWithMessage:
Expand Down
7 changes: 0 additions & 7 deletions pymarshal/__init__.py

This file was deleted.

7 changes: 7 additions & 0 deletions pymarshaler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__version__ = '0.1.0'
__all__ = ['marshal', 'utils', 'arg_delegates', 'errors']

from pymarshaler import marshal
from pymarshaler import utils
from pymarshaler import arg_delegates
from pymarshaler import errors
4 changes: 2 additions & 2 deletions pymarshal/arg_delegates.py → pymarshaler/arg_delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import dateutil.parser as parser

from pymarshal.errors import UnknownFieldError, InvalidDelegateError
from pymarshal.utils import is_user_defined, is_builtin
from pymarshaler.errors import UnknownFieldError, InvalidDelegateError
from pymarshaler.utils import is_user_defined, is_builtin


def _apply_typing(param_type, value: typing.Any) -> typing.Any:
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions pymarshal/marshal.py → pymarshaler/marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import jsonpickle

from pymarshal.arg_delegates import ArgBuilderFactory
from pymarshal.errors import MissingFieldsError
from pymarshaler.arg_delegates import ArgBuilderFactory
from pymarshaler.errors import MissingFieldsError


def unmarshal_str(cls, data: str):
Expand Down Expand Up @@ -53,7 +53,7 @@ def unmarshal(cls, data: dict):
try:
return _unmarshal(cls, data)
except ValueError:
raise ValueError(f'Failed to pymarshal {data} to class {cls.__name__}')
raise ValueError(f'Failed to pymarshaler {data} to class {cls.__name__}')


def marshal(obj, indent=2) -> str:
Expand All @@ -72,7 +72,7 @@ def marshal(obj, indent=2) -> str:
>>> test_instance = Test('foo', indent=0)
>>> data = pymarshal(test_instance)
>>> data = pymarshaler(test_instance)
>>> print(data)
'{name: foo}'
"""
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
long_description = fh.read()

setuptools.setup(
name="pymarshal",
name="pymarshaler",
version="0.1.0",
author="Hernan Romer",
author_email="[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_classes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
from typing import List, Dict

from pymarshal.arg_delegates import ArgBuilderDelegate
from pymarshaler.arg_delegates import ArgBuilderDelegate


class EqualityBuiltIn:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_marshaling.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
import unittest

from pymarshal import marshal
from pymarshal.arg_delegates import ArgBuilderFactory
from pymarshal.errors import MissingFieldsError, UnknownFieldError
from pymarshaler import marshal
from pymarshaler.arg_delegates import ArgBuilderFactory
from pymarshaler.errors import MissingFieldsError, UnknownFieldError

from tests.test_classes import *

Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from pymarshal.utils import is_user_defined, is_builtin
from pymarshaler.utils import is_user_defined, is_builtin
from tests.test_classes import *


Expand Down

0 comments on commit 04c879c

Please sign in to comment.