Skip to main content

pydantic-to-elastic

A simple CLI utility for converting Pydantic models to Elasticsearch mappings.

Installation

From source

git clone https://github.com/malinkinsa/pydantic-to-elastic.git && cd pydantic-to-elastic
pip install .

CLI options

Prop Description Required Default value
--input Path to the file containing Pydantic models. True
--output Output type of result. Possible values: "console" or "file". False console
--output_path Path and filename to save the output file (required if --output is set to 'file'). False
--output_format Output format for JSON data. Use 'json' for compact single-line JSON or 'pretty' for pretty-printed JSON with 4-space indentation. False json
--submodel_type Specifies the submodel type. Possible values: "nested" or "object" False nested
--text_fields List of fields that must be of type 'text'. Can be specified multiple times. False
--flattened_fields List of fields that must be of type 'flattened'. Can be specified multiple times. False

Usage

For example, you have a model user_models.py

from pydantic import BaseModel
from typing import List

class Address(BaseModel):
    street: str
    city: str
    zip_code: str

class User(BaseModel):
    name: str
    age: int
    address: Address
    hobbies: List[str]

Execute the command for converting these models into mapping json:

pydantic2es --input ./user_models.py --output_format pretty

And you will obtain the following result:

{
    "mappings": {
        "properties": {
            "name": {
                "type": "keyword"
            },
            "age": {
                "type": "integer"
            },
            "address": {
                "type": "nested",
                "properties": {
                    "street": {
                        "type": "keyword"
                    },
                    "city": {
                        "type": "keyword"
                    },
                    "zip_code": {
                        "type": "keyword"
                    }
                }
            },
            "hobbies": {
                "type": "keyword"
            }
        }
    }
}

Download files

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

Source Distribution

pydantic_to_elastic-0.0.4.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

pydantic_to_elastic-0.0.4-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_to_elastic-0.0.4.tar.gz.

File metadata

  • Download URL: pydantic_to_elastic-0.0.4.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for pydantic_to_elastic-0.0.4.tar.gz
Algorithm Hash digest
SHA256 25f41b49ad2671367771afdd19d3a4bb94c5b3dad3b0f10dae82eecbe837e185
MD5 39ccdc88b98e9ce15d9fc6cffaa6c58b
BLAKE2b-256 738d9d7b635f1cadcdc777095ad633a9fcaa19bc39273ac5b661c03000efe56a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydantic_to_elastic-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 58d4a7b17612ccce9ef403c96941fecf0239c016607e4ae764b0ef1d4e5908af
MD5 3590fdcef52b56faba08d4ea13f02acf
BLAKE2b-256 b55e9fe968fc84a89db03edef4f62d28a77dfaa05c967238ec9057820b1001cf

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page