Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/illagrenan/django-numpy-json-encoder
Django JSON encoder with numpy support
https://github.com/illagrenan/django-numpy-json-encoder
django json numpy python
Last synced: 6 days ago
JSON representation
Django JSON encoder with numpy support
- Host: GitHub
- URL: https://github.com/illagrenan/django-numpy-json-encoder
- Owner: illagrenan
- License: mit
- Created: 2018-05-30T19:42:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-10T13:52:11.000Z (about 6 years ago)
- Last Synced: 2024-12-15T19:09:54.415Z (17 days ago)
- Topics: django, json, numpy, python
- Language: Python
- Size: 21.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
=========================
Django numpy JSON encoder
=========================.. image:: https://img.shields.io/pypi/v/django-numpy-json-encoder.svg
:target: https://pypi.python.org/pypi/django-numpy-json-encoder
:alt: PyPi.. image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://pypi.python.org/pypi/django-numpy-json-encoder/
:alt: MIT.. image:: https://img.shields.io/travis/illagrenan/django-numpy-json-encoder.svg
:target: https://travis-ci.org/illagrenan/django-numpy-json-encoder
:alt: TravisCI.. image:: https://img.shields.io/coveralls/illagrenan/django-numpy-json-encoder.svg
:target: https://coveralls.io/github/illagrenan/django-numpy-json-encoder?branch=master
:alt: Coverage.. image:: https://img.shields.io/pypi/implementation/django-numpy-json-encoder.svg
:target: https://pypi.python.org/pypi/django_brotli/
:alt: Supported Python implementations.. image:: https://img.shields.io/pypi/pyversions/django-numpy-json-encoder.svg
:target: https://pypi.python.org/pypi/django_brotli/
:alt: Supported Python versionsIntroduction
------------Subclass of standard Django JSON encoder [1]_ that can encode some numpy types (integers, floats and arrays).
.. [1] https://docs.djangoproject.com/en/dev/topics/serialization/#djangojsonencoder
Installation
------------- Supported Python versions are: ``3.6``, ``3.7`` and ``3.7-dev``.
- Supported Django versions are: ``2.0`` and ``2.1`` (version ``1.11`` should also work)... code:: shell
pip install --upgrade django-numpy-json-encoder
Usage
-----.. code:: python
# -*- encoding: utf-8 -*-
# ! python3import numpy as np
from django.http import JsonResponse
from django.views import Viewfrom django_numpy_json_encoder.numpy_encoder import NumpyJSONEncoder
class ExampleNumpyArrayJSONView(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)