Skip to main content

Aika

Status CI Coverage Downloads per month

License Release Notes PyPI Version Python Versions

About

Time interval parsing utilities for multiple languages.

Details

Aika provides date- and time-range parsing utilities for multiple languages. It is based on dateparser, arbitrary-dateparser, and DateRangeParser, and aims for DWIM-like convenience and usefulness.

Currently, it supports 200 language locales through dateparser, and more specific support for English and German through arbitrary-dateparser. Contributions for other languages are welcome.

Setup

Install the most recent version of Aika.

pip install --upgrade aika

Usage

>>> import datetime as dt
>>> from aika import TimeIntervalParser
>>> 
>>> ti = TimeIntervalParser()
>>>
>>> ti.parse("Sat - Tue")
>>> (dt.datetime(2023, 8, 26, 0, 0), dt.datetime(2023, 8, 29, 23, 59, 59, 999999))
>>>
>>> ti.parse_single("1. Juli")
>>> dt.datetime(2023, 7, 1, 0, 0)

Example Expressions

Aika understands all types of date-/time-range expressions like provided by the packages it is based upon, and works with single dates too. This section enumerates a few examples.

dateparser

Calendar notations
  • Week: 2025W01
  • Month: 2025M02, 2025-02
  • Quarter: 2025Q03
  • Year: 2025
Time deltas
  • Day: -1d, -1 day
  • Week: -1w, -1 week
  • Month: -1M, -1 month
  • Year: -1y, -1 year
  • Quarter: -3M, -3 months
  • Mixed: -3d3h5m30s

arbitrary-dateparser » English

  • now
  • today
  • last week to next friday
  • tomorrow - next week
  • next month
  • december
  • July to December
  • jul 1 to jul 7
  • Sat - Tue
  • in March
  • 2024-08-20

arbitrary-dateparser » German

  • jetzt
  • heute
  • letzte woche bis nächsten freitag
  • morgen - nächste woche
  • nächster monat
  • dezember
  • Juli-Dezember
  • jul 1 to jul 7
  • von Samstag bis Dienstag
  • im März
  • 20. August 2024
  • 20.8.2024
  • 20.08.2024

DateRangeParser » English

  • 1st july
  • March 2024
  • July to December
  • 27th-29th June 2010
  • 30 May to 9th Aug
  • 3rd Jan 1980 -- 2nd Jan 2013
  • Wed 23 Jan -> Sat 16 February 2013
  • Tuesday 29 May - Sat 2 June 2012
  • From 1 to 9 Jul
  • jul 1 to jul 9
  • 14th July 1988
  • Jan 2011 - Mar 2014
  • 07:00 Tue 7th June - 17th July 3:30pm
    Caveat: Times will currently be ignored.

DateRangeParser » German

  • 1. Juli
  • 1. bis 7. Juli
  • März 2024
  • Juli bis Dezember
  • Vom 3. März bis zum 9. März 2024

Advanced Usage

By specifying default_start_time and default_end_time arguments, the daterange boundaries will snap to the given times when they otherwise would be "beginning of day" (00:00) or "end of day" (23:59).

import datetime as dt
from aika import TimeIntervalParser

dr = TimeIntervalParser(
    snap_hours=True,
    default_start_time=dt.time(hour=9),
    default_end_time=dt.time(hour=17),
)
dr.parse("Sat - Tue")
(datetime(2023, 8, 26, 9, 0), datetime(2023, 8, 29, 17, 0))

Troubleshooting

If you see an error message like locale.Error: unsupported locale setting for code like this,

import locale

locale.setlocale(locale.LC_ALL, "de_DE.UTF-8")

you will need to generate the German locales.

apt-get update
apt-get install --yes tzdata locales
locale-gen de_DE.UTF-8

Development

Acquire source code and install development sandbox.

git clone https://github.com/panodata/aika
cd aika
uv venv --seed --python 3.11
source .venv/bin/activate
uv pip install --editable='.[develop,docs,test]'

Run linters and software tests:

source .venv/bin/activate
poe check

Etymology

Aika means "time" in the Finnish language.

Acknowledgements

Metadata

Release files for aika 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aika 0.3.2
File Size Uploaded Provenance Actions
aika-0.3.2.tar.gz 23.9 kB Without provenance Details for aika-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aika 0.3.2
File Interpreter ABI Platform Actions
aika-0.3.2-py3-none-any.whl Python 3 none any Details for aika-0.3.2-py3-none-any.whl

Total release size: 44.3 kB

Release files / aika-0.3.2.tar.gz

Download URL aika-0.3.2.tar.gz
Size 23.9 kB
Tags Source
SHA-256 checksum
How to use checksums
42475d719322cc8abf105853b24a01133689449f63833ae4f5c6b05296a570fc
BLAKE2b-256 checksum
How to use checksums
1bfb34b26b6660ce92cd700a8ceb2d07cc7f6f2e0fadb85d49522d16d9d079eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / aika-0.3.2-py3-none-any.whl

Download URL aika-0.3.2-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
015be6a0404d5a638a54f5f8aae37df67a0d6eee1889f9f05e4d0517a4298084
BLAKE2b-256 checksum
How to use checksums
194bb6586d3b6d873f9ce36b378102eac899945adaea530e4ad04603222c56bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for aika 0.3.2

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page