Skip to main content

A parser and toolkit for the opening_hours in OpenStreetMap written in Rust.

Project description

🐍 Python bindings for OSM Opening Hours

PyPI Doc PyPI - Downloads Coverage

Usage

The pre-compiled package is published for Python 3.9 and above and new releases will adapt to officially supported Python versions.

If you want to install this library with older version of Python, you will need the Rust toolchain (rustc and cargo).

Install opening-hours-py from PyPI, for example using pip:

pip install --user opening-hours-py

Then, the main object that you will interact with will be OpeningHours:

from opening_hours import OpeningHours

oh = OpeningHours("Mo-Fr 10:00-18:00; Sa-Su 10:00-12:00")
print("Current status is", oh.state())
print("This will change at", oh.next_change())

# You can also attach a timezone to your expression. If you use timezone-aware
# dates, they will be converted to local time before any computation is done.
from zoneinfo import ZoneInfo
oh = OpeningHours("Mo-Fr 10:00-18:00; Sa-Su 10:00-12:00", timezone=ZoneInfo("Europe/Paris"))

# The timezone can also be infered with coordinates
oh = OpeningHours("Mo-Fr 10:00-18:00; Sa-Su 10:00-12:00", coords=(48.8535, 2.34839))

# You can normalize the expression
assert str(OpeningHours("24/7 ; Su closed").normalize()) == "Mo-Sa"

The API is very similar to Rust API but you can find a Python specific documentation here.

Features

  • 📝 Parsing for OSM opening hours
  • 🧮 Evaluation of state and next change
  • ⏳ Lazy infinite iterator
  • 🌅 Accurate sun events
  • 📅 Embedded public holidays database for many countries (from nager)
  • 🌍 Timezone support
  • 🔥 Fast and memory-safe implementation using Rust

Limitations

Expressions will always be considered closed before 1900 and after 9999. This comes from the specification not supporting date outside of this grammar and makes the implementation slightly more convenient.

Feel free to open an issue if you have a use case for extreme dates!

Development

To build the library by yourself you will require a recent version of Rust, rustup is usually the recommended tool to manage the installation.

Then you can use poetry to install Python dependencies and run maturin (the building tool used to create the bindings) from a virtualenv.

$ git clone https://github.com/remi-dupre/opening-hours-rs.git
$ cd opening-hours-rs

# Install Python dependancies
$ poetry install

# Enter the virtualenv
$ poetry shell

# Build developpement bindings, add `--release` for an optimized version
$ maturin develop

# Now the library is available as long as you don't leave the virtualenv
$ python
>>> from opening_hours import OpeningHours
>>> oh = OpeningHours("24/7")
>>> oh.state()
"open"

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

opening_hours_py-1.1.1.tar.gz (435.9 kB view details)

Uploaded Source

Built Distributions

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

opening_hours_py-1.1.1-cp39-abi3-win_amd64.whl (6.9 MB view details)

Uploaded CPython 3.9+Windows x86-64

opening_hours_py-1.1.1-cp39-abi3-win32.whl (6.9 MB view details)

Uploaded CPython 3.9+Windows x86

opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_x86_64.whl (7.3 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_i686.whl (7.3 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ i686

opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_armv7l.whl (7.4 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARMv7l

opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_aarch64.whl (7.3 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (7.3 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ s390x

opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (7.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ppc64le

opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (7.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARMv7l

opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

opening_hours_py-1.1.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl (7.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.5+ i686

opening_hours_py-1.1.1-cp39-abi3-macosx_11_0_arm64.whl (7.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

opening_hours_py-1.1.1-cp39-abi3-macosx_10_12_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file opening_hours_py-1.1.1.tar.gz.

File metadata

  • Download URL: opening_hours_py-1.1.1.tar.gz
  • Upload date:
  • Size: 435.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.2

File hashes

Hashes for opening_hours_py-1.1.1.tar.gz
Algorithm Hash digest
SHA256 1dca6fe6111dc4e10d035ea029fce828cd3c9aa4455100f444e931a7ac29fdb1
MD5 6c308c6c872b6e0f9b3ad057e1bf6cf0
BLAKE2b-256 3242cb06d7e84109dace5daee5e98a3b3298272e1338c55b4a48a81f0bf56e5a

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a9c6ed366f857cef3f2a0ab66437b08aec9a7a92a6c1cf0ac244b1a287b6ab1b
MD5 d117c7e0a43bcc45209a3acf2ed89e7b
BLAKE2b-256 63875424e7de946fadfd0decc14ff2b8665bb4d61b3ff705c8a936df1a7eadd7

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-win32.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 3853719028c7da5d8d8627ad62aeb80ead223aa4b0fba766b128480b45acec66
MD5 7f6eb4aeb0129e39aba7724bae9b8962
BLAKE2b-256 f2526aaff51f32b03ac08bead557b8d744332a529f7f1a954457d6d9f9bd8cf1

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2325fa2b11adea4cebe3803f14d3e3000a49673e5a9f77a350e72dfa12631bb6
MD5 ba32921c7314e809ba7dd7b8d7d8ba56
BLAKE2b-256 594c8c6d65b844d72d634c27144e5fccc050e42122a1a7f37bfccd462a3711ad

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 1a96c7ead11b7071570a3fbf002c031ad8c85ef957557d8d32d2ae56b4a93cf6
MD5 e3140802d35570cfdb8ea591b292ce90
BLAKE2b-256 e85de212fa18da3610e55060f96cbd16694a6fd6a6646e7dc63ec06cd66d90c1

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 7f9b8515c0efa7f5041914151ce583c13987bf71d9bc4759cd0ec799ff254095
MD5 92fd5bcf3f12709d8df854b49a687ac0
BLAKE2b-256 5d5fc7fd838bc9da208d477c938c38d2709c1885879a4f620a02e4e97c995e33

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 1722950113e3148c6ed428be63d62ad225489e9dde3a696123fa4df327b355c4
MD5 dfdf425dc6167e670268497cfcff8e31
BLAKE2b-256 6eed134cd677d214ec6226c739bc0bbe8a5793ae21c78c1bb4e8af8ac1535820

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 856a6dbfdf7af9f4fe19c98dd30e421273b65001a258955d42b369df0bc8b659
MD5 7d3bd63a395b188b13fd94865d76b53a
BLAKE2b-256 bbc79251ff724bc1bf4cd800e373e5a4ec009c9f41bf80fad61d81d48d1ac206

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 9c9e0f90b64055834e9453fce6446a7af2b62ef5e65d366eb76889e84b42a494
MD5 fb3c80adc8f5b2e485c4a4b57aad1815
BLAKE2b-256 aca823f5a5e8d4010bae1cde001fe30c996d003ab7895ac463a86ff414a32cd9

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 58efdae911364e9bc888da85e7555fdd968d4e31592290a147d665c06b741fd1
MD5 75873d96d7bce6cf195e55856cc7c731
BLAKE2b-256 7d619c4ca912925535d12860712c57bccf7d6af625937dfb995beca5653729f1

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 afa00d7f5f2b86d6d9cf75be05f8a3cfcab2f07a8bfc503f7356234ecf69c34a
MD5 0af87e90df517a8e18381d659c6d5984
BLAKE2b-256 da2f437dd4990a45df13f546cf8863f52257f4a0b6b937fae09018dc2073581e

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 214e974e6f841b7ac142bd2c7259a9d77b7a1e8fec00ef827cdc9a59548fc9f1
MD5 672e99fa8fccdb8ddc6f30d7112c48db
BLAKE2b-256 2855894a61b604da66606991c93df8f69ae69a7ad41fc92e30820987c2cb1dab

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 15ee378d0a5e39bfe017b97ef2b5e8c2910283aa61f2b90dea457ee820b2472d
MD5 a4b502cdd0b88708eec0f9993f73fd76
BLAKE2b-256 9f819713f25a9239fcafa721f832b6425f3498ffd538bbbfa6b6341703bf7cb7

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d4f7815e315212d946a45d19c7ea4ece9968ea39a3900c9385260b87b068236
MD5 095818b5c6aa159bb32987841186b057
BLAKE2b-256 79bc692c7536bf68ef0205d6fde2143dd5f44d43c7c88aeca612e9e9907d4494

See more details on using hashes here.

File details

Details for the file opening_hours_py-1.1.1-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for opening_hours_py-1.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d7085cd36973633e68ddb892327c4d47bc4f77f62dc7de2eb9fc37e0cc1e7bb4
MD5 76aab909d91895d931b497c2a8b84bc2
BLAKE2b-256 e69e98464b35351c2f32eb3f6b260864f9018f82357a9c877ea08e1b232be6b7

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