Skip to main content

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

Project description

Logo

JSONClasses

Pypi Python Version Build Status License PR Welcome

The modern declarative data flow and data graph framework for the AI empowered generation.

JSONClasses eliminates the separated and redundant coding of data sanitization, data validation, data format converting and data serialization.

JSONClasses transforms all the redundant procedures into declarative annotations and markers defined right on the dataclasses.

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

How JSONClasses Works?

JSONClasses is built on top of Python dataclasses. With the great metaprogramming functionalities that Python dataclasses 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 similar to 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. The era we are living 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 Logic 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, encrypted, hidden from response
  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, types

@jsonclass
class User:
  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.writeonly.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 or any other web frameworks.

from flask import Blueprint, request, jsonify
from models.article import Article

bp = Blueprint('articles', __name__, url_prefix='/articles')

@bp.get('/')
async def articles(request: Request):
  return jsonify(await User.find())

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

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

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

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

Documentation

Read our documentation on bla bla bla.

Database & Web Framework Integrations

Supported Python Versions

jsonclasses supports Python >= 3.9.0.

License

MIT License

JSON Classes logo is designed by Albert Leung.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

jsonclasses-2.6.1.tar.gz (99.5 kB view details)

Uploaded Source

Built Distribution

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

jsonclasses-2.6.1-py3-none-any.whl (188.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsonclasses-2.6.1.tar.gz
  • Upload date:
  • Size: 99.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for jsonclasses-2.6.1.tar.gz
Algorithm Hash digest
SHA256 5a24175b2fc78e5beea523fce5f3926ef3430d8723012f6257cf334668737e39
MD5 20de89e2b152006459154ea93c154b33
BLAKE2b-256 03cf4cd4c060c4815ee2d68000ca28345739aa20d1e5f378e8fc8c1c24cf3580

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonclasses-2.6.1-py3-none-any.whl
  • Upload date:
  • Size: 188.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for jsonclasses-2.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 efe0ef2a7fa5a6c6d80009d76724ef629e1bb88ba7ebf8d96c37bd8f69eb9e10
MD5 246c71ba8aaf410a3e71e67f664be10e
BLAKE2b-256 46c23f43a54d49712b0e204e61edc61ac729f12da7c736c6374c60404eca1604

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