Skip to main content

A Fast date-time library.

Project description

windup: A fast date-time library

windup is a library extends from udatetime and offers an faster datetime object instantiation, serialization and deserialization of date-time strings. windup is using Python's datetime class under the hood and code already using datetime should be able to easily switch to windup. All datetime objects created by windup are timezone-aware. The timezones that windup uses are fixed-offset timezones, meaning that they don't observe daylight savings time (DST), and thus return a fixed offset from UTC all year round.

windup extends some optional formatting options, all the options are in windup.fmt and windup.sep.

  • windup.fmt

    • fmt.date: formatting date string, like '2022-07-17'
    • fmt.time: formatting time string, like '12:12:12'
    • fmt.msec: formatting milisecond string, like '12:12:12.123'
    • fmt.usec: formatting microsecond string, like '12:12:12.2123456'
    • fmt.tz: formatting timezone string, like '2022-07-17T12:12:12.123+08:00'
    • fmt.utc_z: formatting timezone string as Z if UTC, like '2022-07-17T12:12:12.123Z'
  • windup.sep

    • sep.T: set the separator 'T' between date-string and time-string
    • sep.space: set the separator ' ' between date-string and time-string
    • sep.underscore: set the separator '_' between date-string and time-string

Just see the examples below.

>>> windup.from_string("2021-07-15T12:12:12.123456+08:00")
datetime.datetime(2021, 7, 15, 12, 12, 12, 123456, tzinfo=+08:00)

>>> dt = windup.from_string("2021-07-15T12:12:12.123456+08:00")
>>> windup.to_string(dt)
"2021-07-15T12:12:12.123456+08:00"

>>> windup.now()
datetime.datetime(2021, 7, 15, 12, 12, 12, 472467, tzinfo=+08:00)

>>> windup.utcnow()
datetime.datetime(2021, 7, 15, 4, 12, 12, 472467, tzinfo=+00:00)

>>> windup.now_to_string(option=windup.fmt.date | windup.fmt.time | windup.fmt.usec)
"2021-07-15T12:12:12.123456"

>>> windup.utcnow_to_string(option=windup.fmt.date | windup.fmt.time, sep=windup.sep.space)
"2021-07-15 12:12:12"

>>> windup.fromtimestamp(time.time())
datetime.datetime(2021, 7, 15, 17, 45, 1, 536586, tzinfo=+08:00)

>>> windup.utcfromtimestamp(time.time())
datetime.datetime(2021, 7, 15, 10, 14, 53, tzinfo=+00:00)

Installation

Currently only POSIX compliant systems are supported. Working on cross-platform support.

$ pip install windup

You might need to install the header files of your Python installation and some essential tools to execute the build like a C compiler.

$ sudo apt-get install python3-dev build-essential

or

$ sudo yum install python3-devel gcc

Benchmark

$ python scripts/bench_windup.py
Executing benchmarks ...

============ benchmark_parse ============
datetime_strptime 2.7934684499996365
windup_parse 0.20049594300053286
windup is 13.9 times faster

============ benchmark_format ============
datetime_strftime 0.6035372909973375
windup_format 0.31113305999315344
windup is 1.9 times faster

============ benchmark_utcnow ============
datetime_utcnow 0.09793541399994865
windup_utcnow 0.04310180398169905
windup is 2.3 times faster

============ benchmark_now ============
datetime_now 0.14119137199941179
windup_now 0.04639216099985788
windup is 3.0 times faster

============ benchmark_utcnow_to_string ============
datetime_utcnow_to_string 0.6921647540002596
windup_utcnow_to_string 0.29203156699077226
windup is 2.4 times faster

============ benchmark_now_to_string ============
datetime_now_to_string 1.2531362709996756
windup_now_to_string 0.49691468400033045
windup is 2.5 times faster

============ benchmark_fromtimestamp ============
datetime_fromtimestamp 0.09680619402206503
windup_fromtimestamp 0.0611271969974041
windup is 1.6 times faster

============ benchmark_utcfromtimestamp ============
datetime_utcfromtimestamp 0.08515822299523279
windup_utcfromtimestamp 0.04857380600878969
windup is 1.8 times faster

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

windup-0.1.1.tar.gz (13.5 kB view details)

Uploaded Source

File details

Details for the file windup-0.1.1.tar.gz.

File metadata

  • Download URL: windup-0.1.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for windup-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7e39c5b5719b7df4d4ee139603c827b621ae25a3c5aa6ce4f3cedc4bf0d2012a
MD5 9bc64c46b1cd8b99e3ec7cc5e1b33d28
BLAKE2b-256 f696d128423287eec9149def65a6585757151f539aa8d1a67b444dfdd199239d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page