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 PeeweeMapper
db = SqliteDatabase('my_app.db')
class BaseModel(Model):
class Meta:
database = db
class User(BaseModel):
username = CharField(unique=True)
is_active = BooleanField(default=True)
age = IntegerField()
user_elastic_mapping = PeeweeMapper(model=User).load()
SQLAlchemy example
from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer, String, Boolean
from elasticmapper import SQLAlchemyMapper
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
username = Column(String)
is_active = Column(Boolean)
age = Column(Integer)
user_elastic_mapping = SQLAlchemyMapper(model=User).load()
DjangoORM example
from django.db import models
from elasticmapper import DjangoMapper
class User(models.Model):
username = models.CharField(max_length=30)
is_active = models.BooleanField(default=True)
age = models.IntegerField()
user_elastic_mapping = DjangoMapper(model=User).load()
Output for all examples:
{
'id': {'type': 'integer'},
'username': {'type': 'text'},
'age': {'type': 'integer'},
'is_active': {'type': 'boolean'}
}
Documentation
Documentation lives here.
Contributing
PR are welcome! If you want to help, please check the issues and fix one of them. 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
elasticmapper-0.1.9.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for elasticmapper-0.1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a69b0002debc2186a48711552deb3a7def66bcc267274eb3f8cb17137ad862a9 |
|
MD5 | 4733bfc73d21f29aab02364342fee64e |
|
BLAKE2b-256 | 6c2bc10d3e6aec392091e1b946b99e27f3bdc385867c23827edac7a5a3092221 |