Easy Leasy
Easy Leasy is a Python library for defining time-based rules and manipulating time sets.
The idea is to express easily things like "open from 9am to 5pm from Monday to Friday" as a single expression, and then use it both to know if a given time is in the time set, and to compute the next time change.
Usage
You can use the parse_easy_leasy function to parse an expression into a
BaseTimeSet object, which will allow you query that time set.
from easy_leasy import parse_easy_leasy
from datetime import datetime
from zoneinfo import ZoneInfo
p = parse_easy_leasy(
"""
from context import has_pr
let work_hour be when 9:30~13:30 | 14:30~18:30
let work_day be when mon | tue | wed | thu | fri
let business_hour be when work_hour & work_day
let xmas be when 25 & dec
let ny be when 1 & jan
let work be when 1 & may
let holiday be when xmas | ny | work
return business_hour - holiday
""",
dict(has_pr=True),
)
now = datetime.now(tz=ZoneInfo("Europe/Paris"))
print(p.value_at(now))
print(p.next_change(now))
The parse_easy_leasy function takes two arguments: the expression to parse,
and a dictionary of context variables which can either be a boolean or a
BaseTimeSet object.
Language reference
The language is simple and has 3 different statements:
from <namespace> import <name>: import a variable from the context.let <name> be when <expression>: declare a new variable<name>with the value of<expression>.return <expression>: return the value of<expression>.
The only statement that is mandatory is return, which is the expression that
will be evaluated to determine the value of the time set.
Expressions are composed of the different types:
- Hour ranges:
hour:minute~hour:minute - Days of the week:
mon | tue | wed | thu | fri | sat | sun - Days of the month:
1 | 2 | ... | 31 - Months:
jan | feb | ... | dec - Absolutes:
always | never
These expressions can be combined using the same operators as the Python sets:
|: union&: intersection-: difference~: complement
API reference
Everything is based on the BaseTimeSet class, which can also be used directly
from Python.
It has different implementations, which are:
Always: always trueNever: always falseHourRange: a range of hoursDay: a single day of the weekWeekDay: a single day of the monthMonth: a single monthConstant: a constant value
As they are subclasses of BaseTimeSet, they can be used with the standard
Python set operators, for example:
from easy_leasy import Always, Month
p = Always() & Month('jan')
Once you have a BaseTimeSet object, you can use the value_at and
next_change methods to query the time set.
from easy_leasy import Always
from datetime import datetime
from zoneinfo import ZoneInfo
p = Always()
# Check if the time set is true at a given instant
p.value_at(datetime.now(tz=ZoneInfo("Europe/Paris")))
# Get the next time change
p.next_change(datetime.now(tz=ZoneInfo("Europe/Paris")))
Metadata
Release files for easy-leasy 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| easy_leasy-1.0.1.tar.gz | 8.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| easy_leasy-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.8 kB
Release files / easy_leasy-1.0.1.tar.gz
| Download URL | easy_leasy-1.0.1.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bcc85a94c6bba44c893a13382ca681ff3a1940f71b9c8d36400f4ba27e1166a8
|
|
BLAKE2b-256 checksum How to use checksums |
db6b1c663908a06a7c44d174aa48a6b4882055d7f9f5480d7aa81d0f537c7be2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.5 Linux/6.1.0-1027-oem
|
Release files / easy_leasy-1.0.1-py3-none-any.whl
| Download URL | easy_leasy-1.0.1-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
87c71220f3a38052d3980f76dc3e05327bc4b02bea42773cf0d63f43ac761295
|
|
BLAKE2b-256 checksum How to use checksums |
9309f385bb2baf2a995bd5ca577a1f8c5a8154b884d3de8125bdcb96b270c9ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.5 Linux/6.1.0-1027-oem
|
Security for easy-leasy 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.