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
data.

[![Build Status](https://secure.travis-ci.org/balanced/pez.png?branch=master)](http://travis-ci.org/balanced/pez)

## 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.
@staticmethod
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)
pre_serialize(Internal())


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](http://pypi.python.org/pypi/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.

Source Distribution

pez-0.0.2.tar.gz (9.2 kB view details)

Uploaded Source

File details

Details for the file pez-0.0.2.tar.gz.

File metadata

  • Download URL: pez-0.0.2.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pez-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f96fa3fa7d4dbbd7c5debe22ed1518f1c082b4a5853c200a4179dda4fc87c463
MD5 9353d491f008f8d9cf90837301df9e5e
BLAKE2b-256 9b5b94b570590b89c5e15ecf5623863c31838d2b0794a4d3a11ac54996453ba6

See more details on using hashes here.

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