Skip to main content

Coercing data into a normalized form

Project description

[Documentation] [Build Status] [Test Coverage]

This library provides functions that coerce datastructures into normalized forms. For example, converting an arbitrary dict into a form that is suitable for passing to json.dumps.

The tornado framework has a function called recursive_unicode in the tornado.escape module. It is a very simple recursive walk of datastructure that switches on type and transforms string values into unicode strings. I use this in production software regularly and it works like a charm. Or at least it did until my software encountered a deeply nested dictionary and I received a RuntimeError: maximum recursion depth exceeded error in my service log. This is one of the exceptions that strikes fear into most engineers when it rears it’s head in production.

That is the primary reason for this library existing. It provides the same simple string encoding function iteratively instead of recursively. At the same time, the need to coerce values into a normalized string form is something that I’ve had to do repeatedly so it might as well be plopped into a reusable library.

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

coercion-0.0.0.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

coercion-0.0.0-py2.py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 2 Python 3

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