Skip to main content

Python wrapper for Coda.io API

Project description

Pydantic Schemas Generator

Code style: black

What is Pydantic

Pydantic is a python library for data validation and settings management using python type annotations.

Here's an official example from the docs

Why generate schemas?

Normally you just program the schemas within your program, but there are several user cases when code generation makes a lot of sense:

  • You're programming several apps that use the same schema (think an API server and client library for it)
  • You're programming in more than one programming language

Getting started

Installation

pip install pydantic-gen

Usage

First you need to create a YAML file with your desired class schema. See example.yml file.

from pydantic_gen import SchemaGen

generated = SchemaGen('example.yml')

The code is now generated and stored in generated.code attribute. There are now to ways to use the code:

  1. Save it to a file, and use the file in your program.
generated.to_file('generated_schemas.py')
  1. Import the code directly witout saving
generated.to_sys(module_name='generated_schemas')

After running .to_sys() module 'generated_schemas' will be added to sys.modules and become importable like a normal module:

from generated_schemas import GeneratedSchema1

schema = GeneratedSchema1(id=1)

Usage pattern

Recommended usage pattern is creating the yaml files needed for your projects and storing them in a separate repository, to achieve maximum consistency across all projects.

YAML-file structure

schemas - list of all schemas described

name - name of the generated class

props - list of properties of the class using python type annotation. Fields: name - field name, type - field type, optional - bool, if True the type will be wrapped in Optional, default - default value for the field.

config - list of config settings from Model Config of pydantic.

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

pydantic-gen-0.2.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

pydantic_gen-0.2.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file pydantic-gen-0.2.0.tar.gz.

File metadata

  • Download URL: pydantic-gen-0.2.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.7 Windows/10

File hashes

Hashes for pydantic-gen-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4afe97d3ad5bc8b6ca01d278589452c3fc8cdeefd0588986a26299bbc9503151
MD5 3e87e372d1aabbb2ef4f5a131069f800
BLAKE2b-256 377ffd12461678a24f6c58f45e074e3fe2fda76d3ad4aff0f79a93d78dd3f925

See more details on using hashes here.

File details

Details for the file pydantic_gen-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic_gen-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.7 Windows/10

File hashes

Hashes for pydantic_gen-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f307d4e2413b3ea5d950683e01b0b6b94688dcda2a54ef9b9c8553fe3dbcd1f7
MD5 af9122c984c77674674c1b67ac5687f7
BLAKE2b-256 342bb167b8c419f594e4f2ce77991100d5876be5b192a77d8501d5b1e7df5f94

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