es_odm
ODM (Object Document Mapper) for Elasticsearch based on Elasticsearch_dsl and Pydantic. It's also a bridge connecting Mysql and Elasticsearch when using Sqlmodel, which also based on Pydantic.
Installation
Install using pip install -U es_odm.
A Simple Example
import typing
from es_odm import InnerESModel, ESModel, Field, ObjectField
class UserProfileODM(InnerESModel):
"""user profile document"""
user_id: int = Field(None, description="user id")
nickname: str = Field(None, description="user nickname", keyword=True)
avatar_url: str = Field(None, description="user avatar url", keyword=True)
gender: int = Field(None, description="gender")
address: str = Field(None, description="address", keyword=True)
class UserODM(ESModel):
"""user document"""
id: int = Field(None, primary_key=True, description="ID")
username: str = Field(None, description="login name", keyword=True)
profile: typing.Union[ObjectField[UserProfileODM], dict] = Field(
None,
description="user profile",
)
class Config:
"""pydantic BaseModel Config"""
arbitrary_types_allowed = True
class Index:
"""elasticsearch_dsl Document Index config"""
name = 'test-index-name'
settings = {
"number_of_shards": 1,
}
def test_odm_doc():
doc_example = {
"id": 1,
"username": "test_username",
"profile": {
"user_id": 100,
"nickname": "test_nickname",
"gender": 1,
"address": "test address"
}
}
doc = UserODM(**doc_example)
assert doc_example == doc.to_dict()
def test_odm_mapping():
cls = UserODM
cls_mapping = cls._index.to_dict()
es_mapping = {
"settings": {
"number_of_shards": 1
},
"mappings": {
"properties": {
"id": {
"type": "integer"
},
"username": {
"fields": {"keyword": {"type": "keyword"}},
"type": "text"
},
"last_login": {
"type": "date"
},
"profile": {
"properties": {
"user_id": {
"type": "integer"
},
"nickname": {
"fields": {
"keyword": {
"type": "keyword"
}
},
"type": "text"
},
"avatar_url": {
"fields": {
"keyword": {
"type": "keyword"
}
},
"type": "text"
},
"gender": {
"type": "integer"
},
"address": {
"fields": {
"keyword": {
"type": "keyword"
}
},
"type": "text"
}
},
"type": "object"
}
}
}
}
assert es_mapping == cls_mapping
Metadata
Release files for es-odm 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| es_odm-0.0.6.tar.gz | 12.1 kB | Without provenance | Details for es_odm-0.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| es_odm-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for es_odm-0.0.6-py3-none-any.whl |
Total release size: 23.8 kB
Release files / es_odm-0.0.6.tar.gz
| Download URL | es_odm-0.0.6.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
83337988c9c0ac08ee009217a5186d306308e94d17472fb33ee97ebbb4d1fcd6
|
|
BLAKE2b-256 checksum How to use checksums |
5f68e6912fbc32f8ab56da79f3834ac799347b76abbefcf6cb1eaa6ced895278
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9
|
Release files / es_odm-0.0.6-py3-none-any.whl
| Download URL | es_odm-0.0.6-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
241ccd761536dfcceaac5c75afa48840659a0120bd2ab9d275aeb8f854e3799c
|
|
BLAKE2b-256 checksum How to use checksums |
994c44b8050308c6d478cdd799a3e38c6123e050a35c4d8d7b3623cb7ca9453b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9
|
Security for es-odm 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.