Skip to main content

sqlorm4es

A simple and expressive (like peewee) sql-like orm for elasticsearch.

Examples

  • Defining index model in a Django way:
from sqlorm4es import *

class LogCenter(BaseModel):
    __index__ = 'lala'
    __database__ = {
        "host": "127.0.0.1:9200"
    }

    ok = Boolean(default=True)
    lineno = Integer(required=True)
    message = Text(default='xixi')
    timestamp = Date(name="@timestamp", timezone="+8")
    bigbrother = Object(
        head=Text(),
        hand=Object(
            finger=Float(),
            nail=Boolean()
        )
    )
  • Search elasticsearch in a expressive way:
res = LogCenter.select(LogCenter.ok, LogCenter.lineno, 'max(lineno)') \
    .where(((LogCenter.ok == False) & (LogCenter.message != 'error')) |
           (LogCenter.timestamp >= '2017-10-12') |
           (LogCenter.bigbrother.head >> ' ( tough; soft, medium soft ) '))\
    .execute()
  • Note that and(&)/or(|) expression in where can be nested
  • Also support group by aggregation: MAX, MIN, AVG, SUM, COUNT...
  • Also support order by, LIMIT, OFFSET:
res = LogCenter.select('max(lineno)')\
    .group_by(LogCenter.ok, LogCenter.timestamp)\
    .order_by((LogCenter.timestamp, 'asc'))\
    .execute()
  • Manipulate document like a normal python object, value will be validated when assigning it (eg. value in Date Field all stored as UTC):
new_log = LogCenter(ok=False, message='oops', timestamp='2019-10-10')
new_log.bigbrother = {
    "head": 'tough',
    "hand": {
        "finger": "long",
        "nail": "clean"
    }
}
  • Create a single document:
new_log.save()
  • Insert, Delete, Update and Index operation: Coming soon...

Install

Sqlorm4es has been packaged to pypi, so just need one simple command to install it:

pip install sqlorm4es

Elasticsearch driver

Sqlorm4es implemented a simple almost lock-free connection pool based on official Elasticsearch client. As it is lock-free, so i am not sure whether it is thread-safe, but it works fine under my own multi-thread tests :)

  • Note that if you did not set config of your model, it will use the default config as below:
config = {
    'hosts': ['127.0.0.1:9200'],
    'maxsize': 20,
    'sniff_on_start': False,
    'sniff_on_connection_fail': False,
    'sniff_timeout': .1,
    'sniffer_timeout': None,
    'retry_on_timeout': False,
    'timeout': 60,
}

Release files for sqlorm4es 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlorm4es 1.1.5
File Size Uploaded
sqlorm4es-1.1.5.tar.gz 19.8 kB Details

Release files / sqlorm4es-1.1.5.tar.gz

Download URL sqlorm4es-1.1.5.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e61cf8cf407e5d98a41b48f6ed14407d5635fd099853eec192635bfd70eb46bb
BLAKE2b-256 checksum
How to use checksums
ce78906c699f38c174fb5d396979348040e6caf728e6b0b527274b68eb0ac44d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

Release history Release notifications | RSS feed

This release

1.1.5 This release

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page