A parser and toolkit for the opening_hours in OpenStreetMap written in Rust.
Project description
🐍 Python bindings for OSM Opening Hours
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file opening_hours_py-1.1.3.tar.gz
.
File metadata
- Download URL: opening_hours_py-1.1.3.tar.gz
- Upload date:
- Size: 438.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
9e6f60bf41e3e0b6d5b7bfd8e32423b004894e47ef7f6ebd80ddfb83fa7ff467
|
|
MD5 |
41837aca891d149dc20afc0ac5b8be75
|
|
BLAKE2b-256 |
ab10b3a7c9378c187690fd63920a7ce56ff9ce74a0669764d063a234c2421a67
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-win_amd64.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 6.9 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
bd49c3d6efb141627058c52e27ed782165b2ce61803e283fc864eeb3bdc73708
|
|
MD5 |
3fcf6f8085ac8d615fc708571e20b535
|
|
BLAKE2b-256 |
c1e2138ad45190e14e421804113314dfd574cbeef68cd21c13b2193f65f1f2d6
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-win32.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-win32.whl
- Upload date:
- Size: 6.9 MB
- Tags: CPython 3.9+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
b02b5bcb56898a351f6ddb54a437641d3cc45a5c0ea9ebff7fd93c962161ee5a
|
|
MD5 |
faf45720d6888d3d2c288e888d6f65e8
|
|
BLAKE2b-256 |
f5ea16d922617fed902bb1e755f5acaab6807dc9760499e2f060d5228641e8ca
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-musllinux_1_2_x86_64.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 7.3 MB
- Tags: CPython 3.9+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
1e62a4ff83cd84459342faf50249153937a61f651d091367596f33ec5edbd22b
|
|
MD5 |
ab880b8ad70f31ad3b2f5ad3844111bf
|
|
BLAKE2b-256 |
5eae5a2ddb847346c768424061912769e00e921f0c8552363de290928e03347d
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-musllinux_1_2_i686.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-musllinux_1_2_i686.whl
- Upload date:
- Size: 7.3 MB
- Tags: CPython 3.9+, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
424d500c0037a2346baa6f489aa37083fa913859c0a79fe284d51edcf95e4229
|
|
MD5 |
11c93e068660ef35924a0eada4993972
|
|
BLAKE2b-256 |
7c7b77c65486dbff10c8e7ff9fc729324b5032dcb69f95680a95294601291a0c
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-musllinux_1_2_armv7l.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-musllinux_1_2_armv7l.whl
- Upload date:
- Size: 7.4 MB
- Tags: CPython 3.9+, musllinux: musl 1.2+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
b64cce1af359ce077e9d8d89c4e851fb770f405f078b9784ebb08a28dd480362
|
|
MD5 |
8c86bc229144e912a97974ef4bbb74f4
|
|
BLAKE2b-256 |
27320827d3acdae480a3a906b163618156d05ad92a973b50f9945c933ee3df87
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-musllinux_1_2_aarch64.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 7.3 MB
- Tags: CPython 3.9+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
5bde1db3a13ff46eae4c176762e328f72da5e7dfe8a96889e0b8c36381835195
|
|
MD5 |
cfb763f13800bb4a5b00e356dd1e1f90
|
|
BLAKE2b-256 |
52c76c967d9078f3822ba4085899f712b9547bae7cff491c290dc09e262f8d38
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 7.2 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
78fb957cdcdbce00bad100bf8f9237544adbfec80c1d92461c2027ed4d84bca2
|
|
MD5 |
995ec20a7157d6f0ed6913294bab0df7
|
|
BLAKE2b-256 |
92f351077a1eb5b7f030f9b5c110eb3f57884e91ead0faa06fdd6d3b7c78863c
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
- Upload date:
- Size: 7.2 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ s390x
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
70f58f35b2372b1e1d9048985516070f4de2fadf0247c23bf0781908fb9b64ce
|
|
MD5 |
2cf22ad97029d723d970eec4b5d08aa0
|
|
BLAKE2b-256 |
a62cf3931e9b80d6e9970bd4489d1059316423b2b31d7d1250c736ccc59512a0
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
- Upload date:
- Size: 7.4 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ppc64le
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
a2ce0766c43f255967fbc1ff1709f5d22682a93373fecffd59a7e616bfe42266
|
|
MD5 |
73e8cf089567e14f5e2356bb0b150024
|
|
BLAKE2b-256 |
7d13b48d205138379093a91e7ac0bfc5f728ec3e4ce8b351ab40751752bd1e98
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 7.1 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
3cdf9a79880f4c79747afe275b3b67986f88609e8995473a304a8def6cac1721
|
|
MD5 |
9d1b28cc6131f3896866a09e86214aa3
|
|
BLAKE2b-256 |
6f4cd955bd841de663835d0984854e27f013cc64ab35aea9903ad3a3f469ce6f
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 7.2 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
9b1055c01cca3e308265b623ea5134cb4f83a206a496ae3c5c73765e34872fd4
|
|
MD5 |
03f9b08267577d71cfbb6f2f08e3cc94
|
|
BLAKE2b-256 |
4b730792f9fd23fcf0c253ae10d63dd3c258aef0d1ad376ff19bd4252207f5ec
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 7.2 MB
- Tags: CPython 3.9+, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
0a73e672a99767f217248fe85f2936b773cfea9c776cc2a97f81edcb64ea119a
|
|
MD5 |
a3cd4e6e59426a63fa4ffbde8b6aa035
|
|
BLAKE2b-256 |
8a0510987992a5bbd62239e7d40bd5abaec938e1193adbe04d9edcface68411f
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 7.1 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d200cdacd39b39856dcc3eba11101a9761e1ddfcf0943181cddd85bcf8ca7e8d
|
|
MD5 |
2f62f7f7a77fdc841d21123fbc21efad
|
|
BLAKE2b-256 |
823141026f2dcd52067218668cd3e0a934bc0d646862840420956dcdf2cf5e78
|
File details
Details for the file opening_hours_py-1.1.3-cp39-abi3-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: opening_hours_py-1.1.3-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 7.1 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d8cde3c573ba474cb3693067dea09244117a29eb5c579a8f06d1add7e40d2075
|
|
MD5 |
bb097a6da64e0d5483217fd977ffa402
|
|
BLAKE2b-256 |
605289e5c32c66be68c634fa5c58fefd9e6c2fe4e897e2c06afd1bd802111218
|