Metadata-Version: 2.1
Name: Represent
Version: 1.6.0
Summary: Create __repr__ automatically or declaratively.
Home-page: https://github.com/RazerM/represent
Author: Frazer McLean
Author-email: frazer@frazermclean.co.uk
License: MIT
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
License-File: LICENSE
Requires-Dist: six (>=1.8.0)
Provides-Extra: test
Requires-Dist: ipython ; extra == 'test'
Requires-Dist: pytest (>=3.0.5) ; extra == 'test'
Requires-Dist: mock ; (python_version<"3.3") and extra == 'test'

Represent
---------

|PyPI Version| |Documentation| |Travis| |Coverage| |Python Version| |MIT
License|

Installation
~~~~~~~~~~~~

.. code:: bash

    $ pip install represent

Automatic Generation
~~~~~~~~~~~~~~~~~~~~

.. code:: python

    from represent import autorepr


    @autorepr
    class Rectangle:
        def __init__(self, name, color, width, height):
            self.name = name
            self.color = color
            self.width = width
            self.height = height

    rect = Rectangle('Timothy', 'red', 15, 4.5)
    print(rect)

::

    Rectangle(name='Timothy', color='red', width=15, height=4.5)

Declarative Generation
~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    from represent import ReprHelperMixin


    class ContrivedExample(ReprHelperMixin, object):
        def __init__(self, description, radians, shape, color, miles):
            self.description = description
            self.degrees = radians * 180 / 3.141592654
            self.shape = shape
            self._color = color
            self.km = 1.60934 * miles

        def _repr_helper_(self, r):
            r.positional_from_attr('description')
            r.positional_with_value(self.degrees * 3.141592654 / 180)
            r.keyword_from_attr('shape')
            r.keyword_from_attr('color', '_color')
            r.keyword_with_value('miles', self.km / 1.60934)

    ce = ContrivedExample('does something', 0.345, 'square', 'red', 22)

    print(ce)
    from IPython.lib.pretty import pprint
    pprint(ce)

::

    ContrivedExample('does something', 0.345, shape='square', color='red', miles=22.0)
    ContrivedExample('does something',
                     0.345,
                     shape='square',
                     color='red',
                     miles=22.0)

.. |PyPI Version| image:: http://img.shields.io/pypi/v/represent.svg?style=flat-square
   :target: https://pypi.python.org/pypi/represent/
.. |Documentation| image:: https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat-square
   :target: http://represent.readthedocs.io/en/latest/
.. |Travis| image:: http://img.shields.io/travis/RazerM/represent/master.svg?style=flat-square&label=travis
   :target: https://travis-ci.org/RazerM/represent
.. |Coverage| image:: https://img.shields.io/codecov/c/github/RazerM/represent/master.svg?style=flat-square
   :target: https://codecov.io/github/RazerM/represent?branch=master
.. |Python Version| image:: https://img.shields.io/badge/python-2.7%2C%203-brightgreen.svg?style=flat-square
   :target: https://www.python.org/downloads/
.. |MIT License| image:: http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
   :target: https://raw.githubusercontent.com/RazerM/represent/master/LICENSE
