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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pydantic_to_elastic-0.0.1.tar.gz
.
File metadata
- Download URL: pydantic_to_elastic-0.0.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2ace38b25c967f7ca694b61f8add6d0e0c78ac4b11357d45e69853f7e79abe0 |
|
MD5 | 3924fa03352016fc6654413c803eb17a |
|
BLAKE2b-256 | f49b47100bdc56256effee89f215adcaf134cbf713bd2dac32191b25ccf12095 |
File details
Details for the file pydantic_to_elastic-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pydantic_to_elastic-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58953eabcf6fd72a65cecf30861d29fdcd15cecbcb45d3254d0d780da413816c |
|
MD5 | 80b90b3087a3adde1f1723fb56a49698 |
|
BLAKE2b-256 | 82e79325e991823c5eddc9b20a6b17647ff4fd6df39cf90bb2769231f1677044 |