Skip to main content

A package to generate orator DB schemas from a python dict.

Project description

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. :)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

pyschemagen-0.0.4-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file pyschemagen-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pyschemagen-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pyschemagen-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 76106d1a582ea8a76e160525054f13e900caac97b2acf21ba2440b75e8bb6702
MD5 4dd3961100d4b0ef4f9ff66093f71167
BLAKE2b-256 6280bcc22909b5e606ec12b5ec66d67f83c6bd1a5e452f1a22fb6521c6beb62c

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