Skip to main content

makes shitty data more fit (a smarter serializer)

Project description

MorPhit

Usage

    >>> from morphit import Parser
    >>> Parser([], '[1,2,3]')
    [1, 2, 3]

pip install morphit

sudo -H pip install morphit

morphit is a no nonsense parser that takes a template for data and converts whatever you feed it into whatever you want it to be.

Do you have "My data is fucked"? If you find yourself saying any of the following, you may to be entitled to financial compensation.

  • WTF half of these are strings instead of insert type here
  • How do I even convert from insert type A to insert type B
  • I have so much bad data I'm going to have to manually fix
  • I have hundreds of if conditions to fix weird data
  • How the hell am I supposed to fix the type of all these nested objects
  • You're telling me this float is supposed to be a date?...
  • You're telling me that I cant put a datetime object anywhere?
  • I don't know how any of these strings became numbers but...

Features

  • datetime serialization
  	>>> from datetime import date
    >>> Parser(str, datetime(2018, 1, 31, 6, 17, 45, 547000))
    "2018-01-31T06:17:45.547"
  • deep serialization of dicts
  • supports custom serializers using methods/lambda functions
  • templated parsers
  • nested templated parsers

Supported Conversions

  • any -> list
  • any -> object
  • any -> tuple
  • any -> type
  • any -> str
  • dict -> str[json]
  • dict -> dict
  • dict -> list
  • dict -> tuple
  • datetime -> str
  • datetime -> str[json]
  • datetime -> int
  • datetime -> float
  • datetime.time -> str
  • datetime.date -> str
  • float -> str
  • float -> float
  • float -> list
  • float -> tuple
  • float -> type
  • float -> datetime
  • int -> str
  • int -> int
  • int -> list
  • int -> tuple
  • int -> datetime
  • int -> type
  • list -> str[json]
  • list -> list
  • list -> tuple
  • tuple -> str[json[list]]
  • tuple -> list
  • tuple -> tuple
  • none -> str
  • none -> bool
  • none -> list
  • none -> tuple
  • str -> bool
  • str -> datetime
  • str -> dict
  • str -> list
  • str -> tuple
  • str[int] -> float
  • str[int] -> int
  • str[float] -> float
  • str[float] -> int
  • str -> type
  • str[iso8601] -> datetime
  • str[iso8601] -> float
  • str[unicode] -> any string conversions
  • str[python] -> any string conversions

iso8601 a date string formatted to the iso8601 spec json a json encoded equivilent of the data unicode strings that get messed up with u' ex: "[u'this',u'that']" python strings that are weirdly single quoted ex: "['photo', 2, 'pic', 'pics']"

Installation

pip3 install morphit

sudo -H pip3 install morphit

Deploy

Build: python3 setup.py build Test python setup.py test Install: python3 setup.py install

Deploy

  • Run tests as outlined above
  • Make sure you bump the version
  • Check venv is active
python3 setup.py sdist bdist_wheel
twine upload dist/*

Development

virtualenv --python=python3 venv
source ./venv/bin/activate
python setup.py easy_install
pip install -r requirements-dev.txt

Roadmap

  • Custom exceptions for bad casting (int/list/tuple -> dict)
  • Add strict parameter that enables enforcement of keys and list/tuple length
  • Add default parameter that remplaces None or non existing values with a specified default
  • Add fallback parameter that accepts a value or a lambda function to replace the value

BUGS

Should output float

    >>> Parser({'asdf':[1.0]}, {'asdf':1000})
    {'asdf': [1000]}

Contributing

Read CONTRIBUTING_.

Make a PR and I'll give it a look

Odds are good / the goods are odd

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morphit-1.0.3.tar.gz (5.3 kB view details)

Uploaded Source

Built Distributions

morphit-1.0.3-py3.7.egg (8.2 kB view details)

Uploaded Source

morphit-1.0.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file morphit-1.0.3.tar.gz.

File metadata

  • Download URL: morphit-1.0.3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.3

File hashes

Hashes for morphit-1.0.3.tar.gz
Algorithm Hash digest
SHA256 d2ff4e66da85c98d8e861dc6f18787521ece9186cb135ce6d213d22f99714db3
MD5 d6a5c2650470fedbd3a4f8a32ba55f9b
BLAKE2b-256 25fa52e1621ad459d17518f1aadb581e3b82aca23decf563d675235d535cc07e

See more details on using hashes here.

Provenance

File details

Details for the file morphit-1.0.3-py3.7.egg.

File metadata

  • Download URL: morphit-1.0.3-py3.7.egg
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.3

File hashes

Hashes for morphit-1.0.3-py3.7.egg
Algorithm Hash digest
SHA256 a8ffe63d9842b6327bf53380927ff9c33ad412967830ae51178f784f3213873b
MD5 cf7eec2c4bd498f53ad25eb75c63897d
BLAKE2b-256 e429b66ca4ce159933fc7c1bcd3dfce3bb6cd92925bf0d70e861bf4f14f4f184

See more details on using hashes here.

Provenance

File details

Details for the file morphit-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: morphit-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.3

File hashes

Hashes for morphit-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b7bf565445473d89d3e09e396dd8073508c517314e000d7cbdf899925e6178a5
MD5 705b1c1969faa2f7c2726d90e8280ae7
BLAKE2b-256 5eaa0d97a6b3dea3f4e839b267d7cb2477a37f982587e55a608427ac11e8d793

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page