Skip to main content
https://travis-ci.org/rebeccaframework/rebecca.todict.png?branch=master

rebecca.todict

rebecca.todict is API and directive converting object to dict.

INSTALL

Install using pip or easy_install.:

$ pip install rebecca.todict
$ easy_install rebecca.todict

USAGE

rebecca.todict privides includeme hook that will set up set_todict directive.:

config.include('rebecca.todict')

using with paste deploy:

pyramid.includes = rebecca.todict

register todict adapter

by directive

To register todict adapter, you can use set_todict directive.:

config.set_todict(Person, person_to_dict)

That register todict adapter converging Person object to dict.

You can register named adapter too:

config.set_todict(Person, person_to_dict_short, name="short")

by todict_decorator

todict_decorator register todict Adapter casually.:

@todict_config(Person)
def person_to_dict(request, person):
    return dict(....)

using todict API

Registered adapters are used by todict API:

from rebecca.todict import todict

d = todict(request, person)
d = todict(request, person, name="short")

JSON Renderer using todict API

rebecca.todict.renderers.json_renderer_factory is factory of renderer using todict API.

to use this renderer, register renderer factory:

config.add_renderer('.json', 'rebecca.todict.renderers.json_renderer_factory')

specify “.json” renderer on view_config or add_view:

@view_config(renderer="short.json")
def person_list(request):
    return dict(people=[Person(), Person()])

the renderer use todict Adapters named “short”.

Contributors

  • Atsushi Odagiri, Original Author

  • Yusuke Muraoka

Changelog

0.5 (2013-09-22)

  • fix content type using json renderer #1

0.4 (2013-08-31)

  • fix conflict multi todict registration for the same name and different type

0.3 (2013-08-31)

  • fix conflict multi todict registration

0.2 (2013-03-02)

  • add json renderer using todict API

  • todict_config decorator

0.1 (2013-02-16)

first commit

Release files for rebecca.todict 0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rebecca.todict 0.5
File Size Uploaded
rebecca.todict-0.5.zip 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rebecca.todict 0.5
File Interpreter ABI Platform
rebecca.todict-0.5-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 14.2 kB

Release files / rebecca.todict-0.5.zip

Download URL rebecca.todict-0.5.zip
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b64323a41ba1fbed59ad95435fd93fb88053fa4d7617f8240083893158cb2b96
BLAKE2b-256 checksum
How to use checksums
bc068350aa76c3c31bff4f82b3443ad9060d19dbd20ece1caeefcd3f26a938c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / rebecca.todict-0.5-py2.py3-none-any.whl

Download URL rebecca.todict-0.5-py2.py3-none-any.whl
Size 5.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4ee74ee35ecd132966e9a36641250af42cba94a6db65cc25cc2b2c84be2d50cb
BLAKE2b-256 checksum
How to use checksums
a117700f5f77226bac4b7568a37c677275394a22d361ffda4266dc96cf8aff16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.5 This release

2 release files

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page