# pydantic-to-elastic
A simple CLI utility for converting Pydantic models to Elasticsearch mappings.
### Installation
#### From source
```bash
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`
```python
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:
```bash
pydantic2es --input ./user_models.py --output_format pretty
```
And you will obtain the following result:
```json
{
"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"
}
}
}
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/malinkinsa/pydantic-to-elastic",
"name": "pydantic-to-elastic",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "pydantic elasticsearch mappings es, elastic",
"author": "Sergey Malinkin",
"author_email": "malinkinsa@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f4/9b/47100bdc56256effee89f215adcaf134cbf713bd2dac32191b25ccf12095/pydantic_to_elastic-0.0.1.tar.gz",
"platform": null,
"description": "# pydantic-to-elastic\n\nA simple CLI utility for converting Pydantic models to Elasticsearch mappings.\n\n### Installation\n\n#### From source\n```bash\ngit clone https://github.com/malinkinsa/pydantic-to-elastic.git && cd pydantic-to-elastic\npip install .\n```\n\n### CLI options\n| Prop | Description | Required | Default value |\n|:----------------|:-----------------------------------------------------------------------------------------------------------------------------------|:---------|:--------------|\n| --input | Path to the file containing Pydantic models. | True | |\n| --output | Output type of result. Possible values: \"console\" or \"file\". | False | console |\n| --output_path | Path and filename to save the output file (required if --output is set to 'file'). | False | |\n| --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 |\n| --submodel_type | Specifies the submodel type. Possible values: \"nested\" or \"object\" | False | nested |\n| --text_fields | List of fields that must be of type 'text'. Can be specified multiple times. | False | |\n\n### Usage\nFor example, you have a model `user_models.py`\n```python\nfrom pydantic import BaseModel\nfrom typing import List\n\nclass Address(BaseModel):\n street: str\n city: str\n zip_code: str\n\nclass User(BaseModel):\n name: str\n age: int\n address: Address\n hobbies: List[str]\n```\n\nExecute the command for converting these models into mapping json:\n```bash\npydantic2es --input ./user_models.py --output_format pretty\n```\n\nAnd you will obtain the following result:\n```json\n{\n \"mappings\": {\n \"properties\": {\n \"name\": {\n \"type\": \"keyword\"\n },\n \"age\": {\n \"type\": \"integer\"\n },\n \"address\": {\n \"type\": \"nested\",\n \"properties\": {\n \"street\": {\n \"type\": \"keyword\"\n },\n \"city\": {\n \"type\": \"keyword\"\n },\n \"zip_code\": {\n \"type\": \"keyword\"\n }\n }\n },\n \"hobbies\": {\n \"type\": \"keyword\"\n }\n }\n }\n}\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple CLI utility for converting Pydantic models to Elasticsearch mappings",
"version": "0.0.1",
"project_urls": {
"Homepage": "https://github.com/malinkinsa/pydantic-to-elastic"
},
"split_keywords": [
"pydantic elasticsearch mappings es",
" elastic"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "82e79325e991823c5eddc9b20a6b17647ff4fd6df39cf90bb2769231f1677044",
"md5": "80b90b3087a3adde1f1723fb56a49698",
"sha256": "58953eabcf6fd72a65cecf30861d29fdcd15cecbcb45d3254d0d780da413816c"
},
"downloads": -1,
"filename": "pydantic_to_elastic-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "80b90b3087a3adde1f1723fb56a49698",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7829,
"upload_time": "2024-11-17T21:08:22",
"upload_time_iso_8601": "2024-11-17T21:08:22.636606Z",
"url": "https://files.pythonhosted.org/packages/82/e7/9325e991823c5eddc9b20a6b17647ff4fd6df39cf90bb2769231f1677044/pydantic_to_elastic-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f49b47100bdc56256effee89f215adcaf134cbf713bd2dac32191b25ccf12095",
"md5": "3924fa03352016fc6654413c803eb17a",
"sha256": "a2ace38b25c967f7ca694b61f8add6d0e0c78ac4b11357d45e69853f7e79abe0"
},
"downloads": -1,
"filename": "pydantic_to_elastic-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "3924fa03352016fc6654413c803eb17a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6550,
"upload_time": "2024-11-17T21:08:24",
"upload_time_iso_8601": "2024-11-17T21:08:24.318204Z",
"url": "https://files.pythonhosted.org/packages/f4/9b/47100bdc56256effee89f215adcaf134cbf713bd2dac32191b25ccf12095/pydantic_to_elastic-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-17 21:08:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "malinkinsa",
"github_project": "pydantic-to-elastic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pydantic-to-elastic"
}