Are there any datetime.tzinfo implementations in C?

2024/10/11 3:25:26

I've been working on a Python library that uses a C extension module to do ISO 8601 parsing.

Part of that work requires the creation of tzinfo objects, which is by far the slowest part of the parse. Calls out to Python implementations of tzinfo (currently pytz.FixedOffset) are simply too slow.

In Python 3.7, datetime.timezone is finally exposed to the C-API. My code takes adavantage of it, and gets a tremendous performance boost from using a C implementation instead of a Python one. I'd love to find a similar C implementation that I could use for Python < 3.6. Perhaps a "backport" of 3.7's datetime.timezone?

I've seen many Python implementations of tzinfo (pytz, datetuil.tz, django.utils.timezone, psycopg2.tz) but none in C.

Are there C implementations of tzinfo (besides datetime.timezone)?

Answer

After searching some more, I ended up finding an implementation in Pendulum's low level ISO 8601 parser.

Edit: This implementation was eventually used in my backport of datetime.fromisoformat

https://en.xdnf.cn/q/118375.html

Related Q&A

How to open telnet as a textfile rather than a binary file

So I was trying to use the read_until method in telnet but then ran into the error: Traceback (most recent call last): File "c:\Users\Desktop\7DTD Bot\test.py", line 44, in <module> tn.…

The algorithm for dividing the range of subnet

There is a interesting algorithm, wrt dividing the range of subnet.I have a subnet,such as 192.168.1.0/24 or 192.168.1.248/22, and so on. And we know that /24 or /22 stands for networks and (32 - 24) o…

Look if a string starts with the ending characters of another string?

I want to see if ending of one string is similar to starting of another stringif i have a string a="12345678" and b="56789" i want to update a as 123456789these two strings are in …

Dict and List Manipulation Python

I have two files one has key and other has both key and value. I have to match the key of file one and pull the corresponding value from file two. When all the key and value are in plain column format …

Python - input of file path

this code works fine when I put the path of the file myself. but when I want to get it from users raw_input() it doesnt work. what can I do?import string import randomprint "enter number between …

libmproxy and mitmproxy documentation

I am new to the mitmproxy world. I need to write a python script that would log all the requests made from a certain app on Genymotion emulator. Now, I learned that mitmproxy can be helpful for my requ…

Printing mutiple HTML tables using tabulate in python

I want to produce two HTML tables using tabulate package, but I am only able to produce one table and send mail.Is it possible to put more than one html table into a message sent with smtplib and email…

Why am I getting presentation error in python list?

My code is following: d = [int(d) for d in input().split()]l = [] c = 1 for i in range(len(d)):if d[i] not in l:l.append(d[i])c += 1for i in range(len(l)):print(l[i], end=" ")Evaluation: Inpu…

Calculating BLEU score between two sumamries in python

prediction = "I am ABC. I have completed my bachelors degree in computer application at XYZ University and I am currently pursuing my masters degree in computer application through distance educat…

Pivot a dataframe with duplicate values in Index

I have a pandas dataframe like thissnapDate instance waitEvent AvgWaitInMs 0 2015-Jul-03 XX gc cr block 3-way 1 1 2015-Jun-29 YY gc current b…