22

I'm trying to implement timezone awareness in my Python application, and I have come across two different Python modules that implement this feature: pytz and python-dateutil. What is the difference between these two modules?

(pytz) http://pytz.sourceforge.net/

(dateutil) https://dateutil.readthedocs.io/en/stable/

Asker
  • 1,299
  • 2
  • 14
  • 31
fangsterr
  • 3,670
  • 4
  • 37
  • 54
  • http://stackoverflow.com/questions/631035/python-tzinfo-and-daylight-time, in case you haven't found this yet. – John Mar 18 '12 at 04:29
  • I've already looked at that, and I still don't really get what the differences between them are – fangsterr Mar 18 '12 at 16:48
  • Looking at some examples from both packages, Pytz allows you to use more customizable global time formatting standards [http://msdn.microsoft.com/en-us/library/az4se3k1.aspx] than Python-dateutil – Switch Mar 21 '12 at 06:57

5 Answers5

24

This article gives a nice overview of the differences between the two libraries, with the biggest difference apparently being the correctness of DST edge cases (where dateutil.tz has advantage).

Berislav Lopac
  • 16,656
  • 6
  • 71
  • 80
  • 2
    And even that biggest difference is gone now. "[T]his problem was not solved until Python 3.6 with the introduction of PEP 495, which added the fold attribute to the datetime class." – viam0Zah Jul 26 '20 at 18:40
5

They both provide useful support for dealing with timezones. I've personally used pytz in my django applications and found it useful and easy to work with. Hope my two cents helps.

Peter Tseng
  • 1,294
  • 1
  • 12
  • 15
1

I use both packages. I don't personally like the way python-dateutil is packaged (the whole this version of python 2 and this version for python 3), it used to not even be on pypi. python-dateutil is great for parsing, even if it is somewhat slow (it is parsing though). I'd bet my money on the pytz package becoming the standard for timezones.

BenH
  • 894
  • 8
  • 7
0

I personally would prefer pytz package as well. python-dateutil is a little strange to use and somewhat slow

Stanley Tang
  • 256
  • 2
  • 7
-1

pytz has the predefined time zones avialable in simple call methods such as 'Asia/kolkata' for 'kolkata' and dateutil will use all the time zones available in your operating system. for the common time zones they are one available in pytz. That is the main difference between both of them, but pytz is less complicated.