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.2.tar.gz (436.7 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.2-cp39-abi3-win_amd64.whl (6.9 MB view details)

Uploaded CPython 3.9+Windows x86-64

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

Uploaded CPython 3.9+Windows x86

opening_hours_py-1.1.2-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.2-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.2-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.2-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.2-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.2-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.2-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.2-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.2-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.2-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.2-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.2-cp39-abi3-macosx_10_12_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for opening_hours_py-1.1.2.tar.gz
Algorithm Hash digest
SHA256 84bc094bcf23794cafac6ae963fd3bcab7fdf853f306821763dbfa0470633287
MD5 583f65eff863c574cc0be950a9365026
BLAKE2b-256 34a079eaa57eb2313471e122be676200a35aa245addc416603cd53dd74be030b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9e9561cd5f368acebdb37b9d8f2979f8ff2fd323d58348c4d5c848b29e982ebe
MD5 48638cded28e13772ae52aa6dbd4e046
BLAKE2b-256 bc2e32e514c1ab9a2fafbe44b749e83d3b84dfb39a17ccf88b07ba2409eb32ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 af99b913cbee7fbfbc80c71d8240ff1ada2b3e1adb02a148ba6787d8b889a02e
MD5 787358e530f4d8bd5723b92d9e7e36a4
BLAKE2b-256 b362b77fb3ee943e083ce3e9f5fbd85fc4f3fb7d0800568025d739a17545d0c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fd6ab63314d07a03109c6a7dfaeaa05403d4dc08fb20467570feb30a717fd778
MD5 c24edaecc3f7c2cef21b910753a568db
BLAKE2b-256 28f2b928d793a6e2dbdc58be685ba503e357056ed8215548d302c4371ac996e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 43a51b9e90788959fed91bdcccd93754e0e7ee74bf29b95d8cf0ee7a9a75a9ff
MD5 cc58fde03650abedd7baaaa31500e484
BLAKE2b-256 d37dcab0a1e64657485ef5d59cf8044609870a221dfaae99def103cd4c797909

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 93dc9a6f8ccb50666016c65bd9bebfe882e0a79c7bcc1c161e80b3e7685127f5
MD5 0549f76f46b687fe0d2486a9fc996cbe
BLAKE2b-256 232a66d7f9294cdca670a26efd82b8aa1da1c82568e47884407661560aa21bf2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 669cd2922f91c485006901c5ab5946423f6be75e687a576ba6bd239495363ce7
MD5 5a2681ffb496a04b8e82a40e7460d6d5
BLAKE2b-256 92b5bed017ae66999c073a42ea51d7ee72ea6eaf360f3365c930b767cfc678e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 449e59edf6f5197313ad3e7184c3d7e6705943b06c06ce0672db0adf375be1ca
MD5 f10d0a10ba8e784767c081d2a0ea2674
BLAKE2b-256 e8a0028db11147aae254635a46de4cd3deb0c4db4924259e99fc2d6983da6090

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 5bd87bb138160a50ab61a45136a218f3a3c29bec6e42ac464fe0c7a55ba265bc
MD5 cbd17ff00c404a2016c4c530b7d128f9
BLAKE2b-256 f88506cf07537e93d1e1420141d9b26f3d130a39bc9760b96d1ba0f645cc9dcc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 3ef1044141862c1aa5728a51695a79680369a06a27cb13c6372ce0cab7a267a7
MD5 e0a16cf7903954aa9d12343953092237
BLAKE2b-256 4ae24720829b84cf8885252b363d2bb0457580c8d722fbacec9b310e7664ea1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 21ef27f4a03399b8d50e6a288a299f177cb6014d8548c0fab2474962ca322ab7
MD5 8111551cca1b7bd8aa4b36b49e355d58
BLAKE2b-256 5016e841bc99cd958ffab59e7f7427af0513e3faa96def6269b6aa9579dd1872

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6a58d37b33596c11fb8affb2ee0dc11d3edceb0c2cbe33f2b33316eed69cc1e8
MD5 a899bc767551c65a485d0eec55de4bbb
BLAKE2b-256 4b75095e0f5657a2611dc2abd672b7011ba73a19f48ff7a93f669da7aa06213c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 2351a8fd50a15e8fbb8a4259a05166c1adb3357d3813cb3a674d1982c67941f2
MD5 fd8d84bace970e9fd92525955504ec93
BLAKE2b-256 1c4ed9ba2569010f17258d53edcb2c68fc52f6505cab6301d0d8ac129a76d246

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a632205efaea51f119f15e6051e0f1b1f4035d97a3b7034386a601ca808138ab
MD5 a62796ffb9d38d8af8322b3e9a50826a
BLAKE2b-256 8c4229f710c9a28a611451831d619590ed7f684193c61d73942197ee1da430e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.2-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d6cdda8dc7e1a8c834fe3fdd6a32d001169168094845efa913cf78d4aaf3e155
MD5 838b72359ba40c4222ba80a635a48a67
BLAKE2b-256 49ddfa28f677d2ef6348a0fb0fac1a2be4b938c67cfa13f2eaa56772390b4f26

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