Skip to main content

ES datemath and date formatting utilities

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:

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

Uploaded Source

Built Distribution

esdateutil-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: esdateutil-0.1.0.tar.gz
  • Upload date:
  • Size: 11.3 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.1.0.tar.gz
Algorithm Hash digest
SHA256 4def0457779a529e7062b33e0f50cbacfe5fbb31bbb4efee2123007f560da430
MD5 b3e81394c0730f94a95eaf42393f3455
BLAKE2b-256 d979d54fff54c3dadc990d7d66a755381d93bd4cbace50fa6e9092c2e8ebde8a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: esdateutil-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31cc8074b9e0db5f93f7ec591fd6e50ff3d9c08f09e30f65cc360d76f72dc389
MD5 253c47980d6965f00915f5198ca993af
BLAKE2b-256 0862f0cfea2f6ce2508a8022835d1020d6ea7dd98aff2efda65f60a96b75a544

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