Skip to main content

PEZ - Python P(r)e-(Seriali)z(ation)

Project description

# PEZ - Python P(r)e-(Seriali)z(ation)

A python library for serializing python objects from their internal
representation to something that can be displayed externally. e.g. This will
transform a python object into a dictionary.

This can include mapping field names, transforming, and selectively displaying

[![Build Status](](

## Installation

pip install pez

## Example

import pez
import json

# Your internal object e.g. a model
class Internal(object):
field1 = 123

field2 = 1
field3 = 2

# How you want to expose the model to the world
class InternalView(pez.FieldMapping):
# pez.Field echos the object as it is.
field1 = pez.Field()

# A static method such as this can allow you to customize the data
# returned.
def calculated_field(ctx, o):
return o.field2 + o.field3

# create an instance of the serialize and map views to models via the
# register method
pre_serialize = pez.Serializer()
pre_serialize.register(Internal, InternalView())

# calling our serializer with an instance of a class will return a
# serializable object (e.g. a dictionary)

See `./examples/` for more examples including how to use with an ORM, how to
use with Flask, and other more advanced use cases.

## Why

PEZ allows you to separate the internal representation of data from your
external view. This is handy for all sorts of scenarios:

* Renaming internal fields without breaking external interfaces
* Hiding or transforming internal data when exposing it
* Adding information to views that doesn't belong in your data models, e.g. URL information

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Write your code **and unit tests**
4. Ensure all tests still pass (`nosetests`)
5. [PEP8]( your code
6. Commit your changes (`git commit -am 'Add some feature'`)
7. Push to the branch (`git push origin my-new-feature`)
8. Create new pull request

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
pez-0.0.2.tar.gz (9.2 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page