Metadata-Version: 2.2
Name: pydantic-to-elastic
Version: 0.0.2
Summary: A simple CLI utility for converting Pydantic models to Elasticsearch mappings
Home-page: https://github.com/malinkinsa/pydantic-to-elastic
Author: Sergey Malinkin
Author-email: malinkinsa@gmail.com
License: MIT
Keywords: pydantic elasticsearch mappings es,elastic
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: requires-dist
Dynamic: summary

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