Skip to main content

Validate, compare, and synchronize Pydantic model schemas with Elasticsearch mappings.

Project description

📦 es-mapping-inspector

es-mapping-inspector is a Python utility to inspect and compare Elasticsearch mappings against Pydantic models. It helps ensure that your Elasticsearch index mapping is consistent with your application's data models.


✨ Features

  • Compare Elasticsearch index mappings with Pydantic models.
  • Inspect and retrieve detailed mapping information from an Elasticsearch index.
  • Extract field definitions from Pydantic models for validation and debugging.
  • Logging-friendly with no default logging configuration (uses NullHandler).

📦 Installation

pip install es-mapping-inspector

🚀 Quick Start

from es_mapping_inspector import compare_es_mapping_with_model, EsMappingInspector, get_pydantic_model_fields
from my_models import MyPydanticModel

# 1. Inspect an Elasticsearch mapping
inspector = EsMappingInspector(es_client=my_es_client, index_name="my_index")
mapping = inspector.get_mapping()

# 2. Compare with a Pydantic model
differences = compare_es_mapping_with_model(
    mapping=mapping,
    model=MyPydanticModel
)
if differences:
    print("Differences found:", differences)

# 3. Get Pydantic model fields
fields = get_pydantic_model_fields(MyPydanticModel)
print(fields)

📚 API Reference

compare_es_mapping_with_model(mapping, model) → dict

Compares an Elasticsearch mapping with a Pydantic model and returns any differences.

Parameters:

  • mapping (dict) – The Elasticsearch index mapping.
  • model (BaseModel) – The Pydantic model to compare against.

class EsMappingInspector

Utility class to retrieve and analyze Elasticsearch mappings.

Methods:

  • get_mapping() – Retrieves the full index mapping from Elasticsearch.
  • (Additional methods as needed)

get_pydantic_model_fields(model) → dict

Returns a dictionary of field names and types from a Pydantic model.


🛠 Development

git clone https://github.com/yourusername/es-mapping-inspector.git
cd es-mapping-inspector
pip install -e ".[dev]"

Run tests:

pytest

📝 Versioning

This package follows Semantic Versioning. Current version: __version__ from es_mapping_inspector.__about__.


📄 License

MIT License – see LICENSE file for details.


💡 Contributing

Pull requests are welcome! Please ensure code style and tests pass before submitting.

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

es_mapping_inspector-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

es_mapping_inspector-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file es_mapping_inspector-0.1.0.tar.gz.

File metadata

File hashes

Hashes for es_mapping_inspector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1fd570133dd25c27faa10a3dc7e8b760448ee15bccdec74aa0d0410a35a5f0eb
MD5 e43ff9c70866f9667606a508bd530e56
BLAKE2b-256 ccf17ce6c5f2fed6d431749ea65fff0fa831731741c59eade10714152d3d3801

See more details on using hashes here.

File details

Details for the file es_mapping_inspector-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for es_mapping_inspector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71ab40c42294b6c3587b683fcb4fed8548418d3b5668c921c495c667f29790c1
MD5 36351301e9561d9a12aa9203ff4095a7
BLAKE2b-256 46230c9005d5e19b5fd35d661233575f28f227fcf3be17808de6790ce4e11498

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