Skip to main content

Django JSON encoder with numpy support.

Project description

PyPi MIT TravisCI Coverage Supported Python implementations Supported Python versions

Introduction

Subclass of standard Django JSON encoder [1] that can encode some numpy types (integers, floats and arrays).

Installation

  • Supported Python versions are: 3.6 and 3.7-dev.

  • Supported Django versions are: 2.0

pip install --upgrade django-numpy-json-encoder

Usage

# -*- encoding: utf-8 -*-
# ! python3

import numpy as np
from django.http import JsonResponse
from django.views import View

from django_numpy_json_encoder.numpy_encoder import NumpyJSONEncoder


class ExampleView(View):
    # noinspection PyMethodMayBeStatic
    def post(self, *args, **kwargs):
        numpy_array = np.random.rand(8, 42).astype(np.float32)

        return JsonResponse(data={'array': numpy_array}, encoder=NumpyJSONEncoder, safe=True)

License

The MIT License (MIT)

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

django-numpy-json-encoder-0.1.3.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

django_numpy_json_encoder-0.1.3-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

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