Skip to main content

A JSON serializer for Kombu (and therefore also Celery) that supports encoding objects by defining to_json and from_json methods.

Project description

Usage
=====

If you want an object to be JSON decodable, you need to define a to_json instance method that returns a dict of json-encodable objects. If you want your object to be encodable, define a from_json class method that takes back that dictionary. You must also use a newstyle class.

An example is below if it would help::

class MyObject(object):

def __init__(self, name):
self._name = name

def to_json(self):
return {'name':self._name}

@classmethod
def from_json(self, obj):
return cls(obj["name"])

Celery Usage
========

ZSON was originally written to allow objects to be passed in Celery. If you want to use zson as your serializer in Celery, you can set this by creating a configuration file and adding::

CELERY_TASK_SERIALIZER = 'zson'
CELERY_RESULT_SERIALIZER = 'zson'
CELERY_ACCEPT_CONTENT = ["zson"]

and then loading this configuration file when you configure your Celery app::

c = celery.Celery('zsearch', backend='amqp', broker='amqp://')
c.config_from_object('celeryconfig')

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

zson-1.0.13.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file zson-1.0.13.tar.gz.

File metadata

  • Download URL: zson-1.0.13.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for zson-1.0.13.tar.gz
Algorithm Hash digest
SHA256 ecc841ae5ad1345c6c785332fbab517cf42995454f2dc162a5f1a103b0ba61be
MD5 3be566574edc4e6efd7a86efb66c7de7
BLAKE2b-256 52bf7a7c30276a83b0fe307ca1db55dc022683fad8a17f553a0bff88abcfbe95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page