Skip to main content

A simple CLI utility for converting Pydantic models to Elasticsearch mappings

Project description

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

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"
            }
        }
    }
}

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_to_elastic-0.0.2.tar.gz (7.4 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.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pydantic_to_elastic-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f067c57a855011a14119b2879dad9439e2befb9ea194209ad2f3ab8a58eb7a7c
MD5 e8e8180e6b9bfa7abe10232d887a6463
BLAKE2b-256 f64d239a15aeb6883e90bc6d744d1c7bc28ea00f5f1dd7ca5b931f98c3e5fc03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydantic_to_elastic-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b03720d392497b98032ccaa02edb15d00b6fd4816914bca61d4f8ba35b8d8a36
MD5 9f2970ce56ca4eff787bcec1c2636ceb
BLAKE2b-256 e29e5ee5b74f6dc29fc4cc5bb9997efa6f96b0546be2a6ca32632978b80311f2

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