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 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elasticmapper-1.0.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

elasticmapper-1.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for elasticmapper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bbe2290c3b6f7b4c29b10bb9a7fd1eae64d5c183d618f70c2c4ce8117ff92caa
MD5 98a8268bb454eeb0d8ba3e997f0dd521
BLAKE2b-256 82debbb68acbd6b1eaa900f1d7c3b8efbba1b082a6ff3cb6bc3562287adcf365

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for elasticmapper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2de004075e5cc162606846645cb19e13b39f6c8ea9e7d1c4d2514fa68277c919
MD5 65eda16b2f0395635e8ec96b34f4fed9
BLAKE2b-256 d0c3d41ac1b15e5671323b25519951adf15a31511278b511eadd4cf963b6db1a

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