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

Uploaded CPython 3.9+Windows x86-64

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

Uploaded CPython 3.9+Windows x86

opening_hours_py-1.1.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0-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.0.tar.gz.

File metadata

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

File hashes

Hashes for opening_hours_py-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c67e2dbfd7cd1d56298a08850e67ce8e380487ee62655979beac4e2cf1c9b29d
MD5 9e3d109efe7a3202939ceda59bfb1277
BLAKE2b-256 958b7e15cf006d94ea67001a99b94deef478fc86956025ef3d40f8ddcd82cfd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7c0ae7cf1375f9a377452a7f2af3e68739afdc7573aad58be89168ec9105d76f
MD5 a59c7583002c1e0e735016582eac2076
BLAKE2b-256 f8d59d5593625c6f821d94f795eef0fe3f293b3ee6ab6fc46bb273896097d5d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 03c16269d88ec851d6d8fcfb61d284d5c78e3eab72cc001075baa55744c4024b
MD5 99393f1b91cefef78e1ec2385da9f221
BLAKE2b-256 6ab5adcb60e0541cd09d2a0cd750af3c7901108f21234da14042d86c4c107ab3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 eb93a9056fbe70c5ec61c79a1769c13c363d30626c60c60153a1bba8dfb2c4d5
MD5 87e1a333292762a44bcaafff28f201b1
BLAKE2b-256 f68a5c4efbc24a520d9c5123b9994c16fa213ff816319501be0b85c4452fe692

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 210a8f5a718d2f43397134b59db516d84e296b210e90e348186db1250fb4db89
MD5 c53a543ba5138aad7b220bc3e5f3133a
BLAKE2b-256 9dec3c24683d787107bf30b68a69d0c543e0a147cc20b08064b95ce6c18a70a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 a7e7e8de000ac72d1cc082eca9f31726de09d154cc97f99767f5461f2576db86
MD5 c45c10d09843684612f61c1b71ac3557
BLAKE2b-256 9bc5bae9453ae22a8700910584cbf688e6cae24f2cba1ad1d84c1f817de65288

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 bdf9d5bb3f071a42e4911fd1b7a9d6b342ba9b15313cbdd862779b60290433e7
MD5 4a8df6ca82b39f3cf18e3866b4bf4016
BLAKE2b-256 bcc8eb95cec96f6abc2a05dda251f1c601f0cea1064f669f2c4dcebb2266739e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 245f2fc4231b73982e3529e73830e0ead20926fc03b9d21fb5469553a6ebdb57
MD5 96355d3a0038a009a628605e3020796b
BLAKE2b-256 ab70a6eeb413540b74e89e74e542aa87db9b970619632429e07e9252bd558fc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 a750c71a3a751222e4d41dddc613f7bd62446bf870afda8d4361469407a56c22
MD5 c5a91a52abdabcaaa28e46940c31358c
BLAKE2b-256 d1798ef655846cf0657c96143e03a53c44734658fdf993024b64cc91206179eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 79e1bf569ef8c1c61abfb193f6151e450bdb9be54ae349e3f7bd905ffcdbee93
MD5 227daa0d484faec059ba4afef4cd5dd4
BLAKE2b-256 ef4aca0445e772fd2c339d2a73acc81d3c592b8b40d637df646389b52ac5e025

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 afa5e468b6ddfeee5de748bf64b9dae47b9e502081f231a231e9ecde1035a7da
MD5 46d70a040b37658551baec8e366b52aa
BLAKE2b-256 b9edce091ad2208fe1ef96a4bd48d29cd46d3d1284b91a13c7c0d4eaeb1962c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 76ba4882b83944635ed36e604e9f5e67afee09d441d8cfacccf71231a0813094
MD5 2f3fe7abe1c52ceb980f7a487537901f
BLAKE2b-256 c9e20f0e9c2af8966457d1c59d6e7c59ef6d398867aa9f552c1eb51a6c6a979d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 1fea87a3a2c056fed1c6168518f7efefae7b7a6a8f8f25036354b36372c234b2
MD5 a7d58b12833adf7fc3000504bffef97d
BLAKE2b-256 91a0c324a4f2f7c6d76b49f69ec63981dc3d546ff6c7b88bef0ab996925efdd6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 61cbe7c7bce3061522e3b65eab576d275617a2a0a3e1089331aa6ba7229ff631
MD5 8054b7acda7e84f1ea892849b088193d
BLAKE2b-256 7d3ac9d11e55535b8771d73cb8c885d81532891ac4c2293cde8f8fc7b75d060c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opening_hours_py-1.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6129a433419514f40f7d62c2a08a33710d31f71b4dd5bcd6b7ed602c2e2e594d
MD5 52b117d569ab709bf3934e85013de853
BLAKE2b-256 9fcffc49f28ba9c102c662e2f1fcb4de424df4aefe0dab0813cf35f2be3e84db

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