Generating ElasticSearch mappings based on ORM's models
Project description
ElasticMapper
ElasticSearch mapper for three ORMs - SQLAlchemy, Peewee, DjangoORM.
Allows you to easily generate ElasticSearch mappings based on models.
Installation
pip install elasticmapper
Basic usage
Peewee example
from peewee import *
from elasticmapper import load, SupportedORMs
db = SqliteDatabase('my_app.db')
class BaseModel(Model):
class Meta:
database = db
class User(BaseModel):
username = CharField(unique=True)
user_elastic_mapping = load(model=User, orm=SupportedORMs.Peewee)
SQLAlchemy example
from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer, String
from elasticmapper import load, SupportedORMs
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
username = Column(String)
user_elastic_mapping = load(model=User, orm=SupportedORMs.SQLAlchemy)
DjangoORM example
from django.db import models
from elasticmapper import load, SupportedORMs
class User(models.Model):
username = models.CharField(max_length=30)
user_elastic_mapping = load(model=User, orm=SupportedORMs.DjangoORM)
Output for all examples:
{
'id': 'int',
'username': 'text'
}
Documentation
elasticmapper.load
- model - required param
A model instance.
- orm - required param
One of the SupportedORMs attributes.
- keyword_fields
A collection that contains attribute names. All of them will have keyword
type in the output mapping.
- include
A collection that contains attribute names. Attributes that are not listed in this collection will not be included in the output mapping.
- exclude
A collection that contains attribute names. Attributes that are listed in this collection will not be included in the output mapping.
- alternative_names
A dictionary that contains attribute names and their new names which will be listed in the output mapping.
For example:
elasticmapper.load(model=..., orm=..., alternative_names={'id': 'obj_id'})
Expected output:
{'obj_id': 'int'}
Contributing
PR are welcome! Thank you for your contribution.
License
Copyright © 2022 Polina Beskorovaynaya ihatemilk
This project has MIT License.
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
Hashes for elasticmapper-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78ded35df1f16fc85d53c30987f387c0dd81a9d338543ac5957cef9e3de102a0 |
|
MD5 | 8b5a875f992fa0a3a85caf6967d6dedd |
|
BLAKE2b-256 | 6087e79d8668fc9a57918c5c7723913ead0ef7d6c0bcc5c24edd36658de4dc55 |