Skip to main content

Patch datetime to use a much quicker strptime implementation.

This ONLY improves strptime when the format string uses padded directives.

This is the list of supported directives (by far the most common):

SUPPORTED_DIRECTIVES = ('%d', '%m', '%Y', '%H', '%M', '%S', '%f')

Check if your date/time format is supported by calling:

datetime.supported_strptime(format_string)
# True if supported, False otherwise

On average, 4 times quicker than the stdlib version, and 50 times as quick when using pypy!

Usage:

# insert this one line
from monkeytime import datetime
# Done migrating code to monkeytime!

from datetime import datetime

# Call it once with the specific format string
# It will build a new function to quickly parse the string, then run it on
# the string you passed it.
dt = datetime.strptime('2014-05-30T12:14:15.123456', '%Y-%m-%dT%H:%M:%S.%f')

# Now, whenever you use that format again, it will use the function it
# built already! All constructed functions are memoized.
# Since we usually only use one or two formats in our code to parse logs
# and such, the performance of constructing it is negligible.

All you need is that one line “from monkeytime import datetime”, and your strptime performance will increase dramatically.

Make sure it is ABOVE your “from datetime import datetime” import line!

Metadata

Release files for monkeytime 0.1.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 monkeytime 0.1.2
File Size Uploaded
monkeytime-0.1.2.tar.gz 3.7 kB Details

Release files / monkeytime-0.1.2.tar.gz

Download URL monkeytime-0.1.2.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
da5b5c8d8346933a3781eda981c0b68e899c2500d8c5349d6e9f2c40ee36c8ab
BLAKE2b-256 checksum
How to use checksums
ebc0ee11b7434b703aa5d0d7fc13e2049237e6fcd52e5a32bd590e080bae94b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.2.1

1 release file

0.2.0

1 release file

This release

0.1.2 This release

1 release file

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