Skip to main content

PySchemaGen

This is a very rudimentary project that allows you to generate a flat but complex schema off of a flat json dict.

I built this because I write a lot of data import systems in my free time just scraping stuff from public APIs or the web and I find it truly tedious to write schemas all the time when im not building anything production ready. so this is just a system to fast track that process by spitting out a schema based on a dictinary.

How do I use it?

from pyschemagen import Parser

if __name__ == '__main__':
    dictionary_data = {
        "keyOne": "value",
        "keyTwo": 1,
        "keyThree": False,
        "keyFour": 1.5,
    }

    # explicitly typing the param names like this is not required. 
    # I'm just doing it to make it clear what goes where. 

    p = Parser(data=dictionary_data, table_name="MyTable")
    p.write_all()

This above method will generate a new module with orator schema definition and model definition automatically generated from the dict that you passed in. Currently this only works with single level dictionaries, though I might build on this in the future.

It will output a directory structure like this:

my_module
|__ __init__.py
|__ config.py
|__ import.py
|__ schema.py
|__ mytable.py
  • config.py sets up your db connection for you
  • import.py sets up a rudimentary import function that will convert the dictionary into the new schema format.
  • schema.py sets up your db schema.
  • mytable.py is the model file for your database.

Currently the schema makes everything nullable other than the primary key and created_at/updated_at fields. This is to insure that the import of your data is not having errors, but you are free to adjust the schema as you see fit. Ideally down the road I'd like to make this system able to accept a list of dicts so that it can evaluate essentially the lowest common denominator of data between them, but that will have to come later.

Dependencies

This project assumes you have Orator-Orm installed. If you have that you are good to go.

Feel free to fork and send PRs my way. :)

Metadata

Release files for pyschemagen 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pyschemagen 0.0.4
File Interpreter ABI Platform
pyschemagen-0.0.4-py3-none-any.whl Python 3 none any Details

Release files / pyschemagen-0.0.4-py3-none-any.whl

Download URL pyschemagen-0.0.4-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76106d1a582ea8a76e160525054f13e900caac97b2acf21ba2440b75e8bb6702
BLAKE2b-256 checksum
How to use checksums
6280bcc22909b5e606ec12b5ec66d67f83c6bd1a5e452f1a22fb6521c6beb62c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.0.4 This release

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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