Skip to main content

Elasticsearch datemath and dateformat parsing library. Zero dependencies

Project description

esdateutil

Provides utilities for handling dates like how Elasticsearch does.

In particular:

  • Datemath parsing and evaluation
  • ES-like datetime string format parsing

The goals of this project are:

  • Be as close to Elasticsearch behaviour as Python makes sensible.
  • No runtime dependencies.
  • Customizability; most functionality should be parameterizable.

This project will be version 1.0 when it provides:

Links

https://pypi.org/project/esdateutil/

Building

Requires pyenv and pyenv-virtualenv to be installed on your machine. Requires pyenv-init (pyenv and pyenv-virtualenv) to be run for pyenv local to work w/ virtualenv

Hitchhiker's Guide to Python Datetimes

One of the consequences of using Python's built-in datetime objects and functions by default is that they can behave very differently from version to version and from Elasticsearch defaults. Below are some of the most important differences in functionality to be aware of.

  • The default date parsing format in Elasticsearch is strict_date_optional_time||epoch_millis. The default parse function of DateMath in this library is datetime.datetime.fromisoformat, but it can be customized with DateMath(date_fn=custom_date_parsing_function). The dateformat module approximates the ES functionality, but is not correct yet. If you are parsing datemath strings containing absolute datetime values, this means:
    • By default, ES supports millisecond epochs as a datetime format, by default we do not.
    • datetime.datetime.fromisoformat only parses from ISO format properly in 3.11+. It is recommended to use a different date_fn if you are using a version below 3.11, such as python-dateutil's parser.parse and parser.isoparse or the iso8601 library.
    • ES strict_date_optional_time allows 2024 or 2024-08 as dates, but Python's fromisoformat does not even in 3.11+. python-dateutil parser.isoparse and iso8601 support this, or you can set a custom date_fn using the dateformat module of this library or the built-in strptime if you need this functionality.
  • The default time resolution in Elasticsearch is milliseconds, whereas in Python datetime it is microseconds. This shouldn't be important unless you are using the optional UNITS_ROUND_UP or another custom round implementation. UNITS_ROUND_UP_MILLIS is provided as an alternative.

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

esdateutil-0.2.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

esdateutil-0.2.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file esdateutil-0.2.0.tar.gz.

File metadata

  • Download URL: esdateutil-0.2.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.1.dev0+g94f810c.d20240519 CPython/3.12.5

File hashes

Hashes for esdateutil-0.2.0.tar.gz
Algorithm Hash digest
SHA256 85c5bd1c8d5d2fae3eec4ac7ec912cf19b6b006980f11c4b8693ff26dfcf394f
MD5 34b86b7edf787e747da6ce2f80f6aadb
BLAKE2b-256 3705dd90645ec6b1740e723956e408eee832d3c176d8fd5baceac006a48b0fb1

See more details on using hashes here.

File details

Details for the file esdateutil-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: esdateutil-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.1.dev0+g94f810c.d20240519 CPython/3.12.5

File hashes

Hashes for esdateutil-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb8e8c0c79613132f99aaaa690a56ca9d3412baa28508fe5a7822966db197861
MD5 5412606f7cf89c775257b9805b582e7b
BLAKE2b-256 5e1b180ca657038343c36443817182ffbb5716be70fb30a14fa667a6ad7a3d1b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page