Skip to main content

The Modern Declarative Data Flow Framework for the AI Empowered Generation.

Project description

JSON Classes

Pypi Python Version Build Status License PR Welcome

The Modern Declarative Data Flow Framework for the AI Empowered Generation.

JSON Classes eliminates the separation and redundant coding of data sanitization, data validation, data format converting, data serialization and data persistent storage.

JSON Classes transforms all the redundant procedures into declarative annotations and markers defined right on the data classes.

Just like how React.js changed the paradigms of frontend development, JSON Classes aims leading the transforming of the insdustry backend development standards.

How JSON Classes Works?

JSON Classes is built on top of Python Data Classes. With the great metaprogramming functionalities that Python Data Classes offers, we can easily extend it into a great DSL for declaring data structures, transforming rules and validation rules.

Why Not Create Another SDL?

GraphQL's Schema Definition Language cannot work well with programming languages' syntax checking and type completion. To support more and more functions, a DSL would become more and more like a programming language.

This is why React.js embedded HTML into JavaScript/TypeScript and Apple built new Swift language features for SwiftUI.

Why Python Is Chosen?

Python is the programming language which is nearest to AI areas. This is an era and a generation empowered by AI. AI algorithms empower products with unimaginable stunning features. A great product should adapt to some level of AI to continue providing great functions for it's targeting audience.

Business Examples

Example 1: Dating App Users

Let's say, you are building the base user functionality for a cross-platform dating app.

The product requirements are:

  1. Unique phone number is required
  2. Password should be secure and encrypted
  3. Gender cannot be changed after set
  4. This product is adult only
  5. User intro should be brief

Let's transform the requirements into code.

from jsonclasses import jsonclass, JSONObject, types

@jsonclass
class User(JSONObject):
  phone_no: str = types.str.unique.index.match(local_phone_no_regex).required #1
  email: str = types.str.match(email_regex)
  password: str = types.str.length(8, 16).match(secure_password_regex).transform(salt).required #2
  nickname: str = types.str.required
  gender: str = types.str.writeonce.oneof(['male', 'female']) #3
  age: int = types.int.min(18).max(100) #4
  intro: str = types.str.truncate(500) #5

Look how brief it is to describe our business requirements. JSON Classes has official support for some databases to store data permanently. If you are building a RESTful API, you can integrate JSON Classes with flask, sanic or any other web frameworks.

from sanic import Blueprint
from sanic.request import Request
from jsonclasses_sanic import response
from jsonclasses_sanic.middlewares import only_handle_json_middleware
from models import User

bp = Blueprint('users')

bp.middleware('request')(only_handle_json_middleware)

@bp.get('/')
async def users(request: Request):
  return response.data(User.find())

@bp.get('/<id:string>')
async def user(request, id):
  return response.data(User.find_by_id(id))

@bp.post('/')
async def create_user(request):
  return response.data(User(**request.json).save())

@bp.patch('/<id:string>')
async def update_user(request, id):
  return response.data(User.find_by_id(id).set(**request.json).save())

@bp.delete('/<id:string>')
async def delete_user(request, id):
  return response.empty(User.delete_by_id(id))

Documentation

Read our documentation on bla bla bla.

Database & Web Framework Integrations

Supported Python Versions

jsonclasses supports Python >= 3.8.

License

MIT License

Project details


Release history Release notifications | RSS feed

This version

0.5.0

Download files

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

Source Distribution

jsonclasses-0.5.0.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

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

jsonclasses-0.5.0-py3-none-any.whl (56.8 kB view details)

Uploaded Python 3

File details

Details for the file jsonclasses-0.5.0.tar.gz.

File metadata

  • Download URL: jsonclasses-0.5.0.tar.gz
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for jsonclasses-0.5.0.tar.gz
Algorithm Hash digest
SHA256 7d649aa64aa7d2594dbfe5bc6ff759385c57916d7f195d6ad9da4463b425f93c
MD5 d17867ab12eedcfcb50fb85bb0474918
BLAKE2b-256 441df07b378b5e259edadba5d9971f9335683e4bd20d79cd677bdb2301294e71

See more details on using hashes here.

File details

Details for the file jsonclasses-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: jsonclasses-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 56.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for jsonclasses-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99f2b21fd3eb89dcefe3da95f54517be6adf5144053f5fa4f16b13072c2731ba
MD5 f50d020d7a6bb4a87cd0c11d6d48414d
BLAKE2b-256 7ed6933fc323f5aa3cc9ba8ef2c37aa65a74d660eeef4882277b8542f440dc3e

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