Skip to main content

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)
    is_active = BooleanField(default=True)
    age = IntegerField()

user_elastic_mapping = load(model=User, orm=SupportedORMs.Peewee) 

SQLAlchemy example

from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer, String, Boolean
from elasticmapper import load, SupportedORMs

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 = 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)
    is_active = models.BooleanField(default=True)
    age = models.IntegerField()

user_elastic_mapping = load(model=User, orm=SupportedORMs.DjangoORM) 

Output for all examples:

{
    'id': {'type': 'integer'},
    'username': {'type': 'text'},
    'age': {'type': 'integer'},
    'is_active': {'type': 'boolean'}
}

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


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.7.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

elasticmapper-0.1.7-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file elasticmapper-0.1.7.tar.gz.

File metadata

  • Download URL: elasticmapper-0.1.7.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for elasticmapper-0.1.7.tar.gz
Algorithm Hash digest
SHA256 c6295f511c5b90379462786dbe79ed79e829891bc0fd4d41aeb265200e5109c6
MD5 dfeb52a468642ece44395a6d99cb1005
BLAKE2b-256 bea447689babd7036c789fd60990a2ed13fcd332637c5acfb99dbb0ea75cb555

See more details on using hashes here.

File details

Details for the file elasticmapper-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: elasticmapper-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for elasticmapper-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 aaf236c16faab9a35e9968787d5ccb91b8ba27a2f0817ec9aed461806e1ab57f
MD5 b04fbc0b4f795ddf151fb7f1f105f03c
BLAKE2b-256 52499d23ff634b792bf3816f27bfdcc5b46e66356de208f231b35b987d08abb5

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