Skip to main content

A package to convert json schema data to a sqlachemy flask file

Project description

Idea

The main idea behind this project is to get a simple web based cruid interface for given JSON Schema files without the need of manual convert these data structures to other formats and handle this redundancy. As JSON seems to be the defacto standard data exchange format for different programming languages and JSON Schema is the natual extension to specify the content of the data, in many cases these are anyway exists, or could easily be generated, these two are the choosen ones.

What it does

This script converts a couple of connected (with filenames $ref) flat (without neested objects) JSON Schema files to a few python scripts:

  • one containing the flask admin / SQLAlchemy data,

  • one to create data in database,

  • one to get all unique names of data (see above),

  • one to convert an object from the database to a python dict,

  • and one to get an order in which new entries in the database should constructed (cause of unique name fields, see above).

Each JSON schema description should contain one variable that is marked with “uniqueName”: true that contains a unique name for this entry. This name should be used to reference this datafield from other JSON Schemas with “$ref”:“FILENAME.schema.json” (see jsonschema_to_sqlalchemy_flask/test/data folder for a simple example). The scripts could be used in the process when the JSON schemas are generated (if they are generated), so the interface is updated accordingly. The default location of the database is the “/tmp” directory, so data should be read and saved elsewhere after creation.

For use this project, create a dir, for example test_js2sf, create an empty init.py file there, insert the following in your code:

from jsonschema_to_sqlalchemy_flask.src import convert_to_sqlalchemy_flask
from jsonschema_to_sqlalchemy_flask.src import convert_to_json_loader
from jsonschema_to_sqlalchemy_flask.src import convert_to_json_dump
from jsonschema_to_sqlalchemy_flask.src import convert_to_unique_name_list_getter
from jsonschema_to_sqlalchemy_flask.src.get_order import get_order
from jsonschema_to_sqlalchemy_flask.src.convert_from_json_schema import convert_flask_admin

to import all stuff and

schema_filename_list = ["filename1.schema.json", "filename2.schema.json"]
flask_filename_without_extension = "flask_main_file"
flask_filename = "test_js2sf/flask_main_file.py"

data = convert_flask_admin(schema_filename_list, flask_filename_without_extension)

to get an intermediate data structure for getting the python code (with existing JSON Schema files filename1.schema.json and filename2.schema.json), and after:

flask_file = convert_to_sqlalchemy_flask.insert_in_template(data)
with open(flask_filename, "w") as fh:
    fh.write(flask_file)

and

json_load_file = convert_to_json_loader.insert_in_template(data)
json_dump_from_database_file = convert_to_json_dump.insert_in_template(data)
unique_name_list_file = convert_to_unique_name_list_getter.insert_in_template(data)
order_list = get_order(data)

to get the python code from. After saving these files (for example “test_js2sf/json_load.py”, “test_js2sf/json_dump.py” and “test_js2sf/name_list.py”), they could be called from commandline as follows:

python -m test_js2sf.json_load --input_filename filename1.json --modelname filename1

with existing filename1.json contains data that fits the filename1.schema.json and its unique name contains “name1” and

python -m test_js2sf.json_dump.py --modelname filename1 --uniquename "name1" --output_filename "equal_to_filename1.json"

or

python -m test_js2sf.name_list.py --modelname filename1

to get all unique names for filename1.schema.json data in database.

Install

install with pip (python 3.10 and new pip version needed):

pip install jsonschema-to-sqlalchemy-flask

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

jsonschema_to_sqlalchemy_flask-0.1.4.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

jsonschema_to_sqlalchemy_flask-0.1.4-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file jsonschema_to_sqlalchemy_flask-0.1.4.tar.gz.

File metadata

File hashes

Hashes for jsonschema_to_sqlalchemy_flask-0.1.4.tar.gz
Algorithm Hash digest
SHA256 4c19fd2410fbc04bebbd12517fe62c7e25fd3f151dd4b6c2384e059b85c9b539
MD5 78f8d8f83b009a129da8fb73d82b7303
BLAKE2b-256 43eec975dc58e0cfa26b5ac3ab603830c86a505e0f578b2351cba978e9e02098

See more details on using hashes here.

File details

Details for the file jsonschema_to_sqlalchemy_flask-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonschema_to_sqlalchemy_flask-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8457fcecdbf0a3c96787cd99a85cc072e0dd55454a85fdea1a186fb574984423
MD5 f57d3800c064d6facea8db561b8093ef
BLAKE2b-256 977a8f4cc1e085c853588e50cbcda73da510105c26884f5f9dec986373f804eb

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