Skip to main content

jsonapi Travis Coveralls github Codacy grade GitHub tag Python versions

A minimalistic JSON API framework in Python with support for graphql-style queries.

jsonapi is heavily inspired by graphql, but aimed at a much simpler use case. The idea is to have a minimal framework for easily building JSON based APIs, that doesn't require any particular frontend technology. The design is inspired in graphql's idea of a single fully customizable endpoint, but instead of defining a specific query language, jsonapi is entirely based on JSON both for the query and the response, requires much less boilerplate code, only works in Python 3, and of course, is much less battle-tested. If you find graphql amazing but would like to try a decaffeinated version that you can setup in 10 lines, then give jsonapi a shot.

Instalation

jsonapi is a single Python file with no dependencies that you can just clone and distribute with your project's source code:

git clone https://github.com/apiad/jsonapi.git

Hello world

To illustrate the usage is best to start with an example. The main class in jsonapi is (wait for it...) JsonApi, which defines all the available commands in the API as public methods:

>>> from jsonapi import JsonApi

>>> class HelloWorld(JsonApi):
...     def say(self, message, args):
...         return message.format(args)

Afterwards, create an instance of this API and call it, passing along either a JSON-enconded string, or a pure Python dictionary, to query either methods or attributes:

>>> api = HelloWorld()

>>> api({"say": { "$message": "Hello {0}!", "$args": "world" }})
{'say': 'Hello world!'}

Moving on

There is more that can be done with jsonapi, read the documentation to learn more:

Contributing

Contributions are highly appreciated. Just fork and submit a pull request. All contributors will be granted credit on the following list:

Changelog

In the roadmap

  • Automatic API documentation.

v0.2.1

  • Support for typed arguments.

v0.2.0

  • Support for meta operators in dictionaries (_count, _items, _keys, _values).
  • The JsonObj constructor now receives either str, dict or a **kwargs mapping.

v0.1.4

  • Support for some meta operators for lists (_count and _items).

v0.1.3

  • Basic implementation of JsonObj for JSON manipulation.

v0.1.2

  • Suport for complex method arguments (parsed via JsonObj).

v0.1.1

  • Suport for plain method arguments.

v0.1

  • Basic layout of the API.
  • Simple attribute and method based navigation.
  • Automatic serialization to a JSON compatible object.
  • Basic documentation.

Colaboration

This project is licensed MIT, so you know the drill. Fork, open a pull request, and make sure to have up-to-date tests with (ideally) a 100% coverage.

MIT License

Copyright (c) 2018 Alejandro Piad

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonapi-simple-0.2.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonapi_simple-0.2.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file jsonapi-simple-0.2.1.tar.gz.

File metadata

  • Download URL: jsonapi-simple-0.2.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.6.7

File hashes

Hashes for jsonapi-simple-0.2.1.tar.gz
Algorithm Hash digest
SHA256 db6be5aa390a7902d945587838113c5804a8f169dd8a6ddb0dc1fc460106316c
MD5 e2399a9f0bd498c93b748d155b33eb5c
BLAKE2b-256 222139b13fb16107e7680b8b2984b6500c39b97a2fbad47edce9b7df2e95e4ca

See more details on using hashes here.

File details

Details for the file jsonapi_simple-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: jsonapi_simple-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.6.7

File hashes

Hashes for jsonapi_simple-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 44f45113de87bb608d8ea4d683023c9176494230eb0c1a258e205c722edbfcd6
MD5 0f3d148ece1a8073df1e3c2a9d6cb56a
BLAKE2b-256 b0a61ca8a6bf59183f1d0e5e6d7f77e26c78a26b4b8e8ad21bc95e6a6331bdc9

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

2 files

This release

0.2.1 This release

2 files

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