From the course: Python Essential Libraries

Introduction to Pendulum - Python Tutorial

From the course: Python Essential Libraries

Start my 1-month free trial

Introduction to Pendulum

- [Instructor] There are quite a few libraries available for working with dates in Python and in this chapter, I'm going to demonstrate one of the more popular ones called Pendulum. And Pendulum has a number of nice benefits to using it. First, it provides pretty much a drop-in replacement for the existing datetime class in Python. So, with a few exceptions, you can use it in places where your code is already using the standard datetime class. It also simplifies using timezones because by default it creates datetime instances that have timezones assigned to them using UTC as the default timezone if you don't specify one. Pendulum also adds some nice utility functions for common scenarios that happen when you write code with work with dates, such as date math, working with durations, and formatting date strings. And finally, Pendulum improves on the existing Python timedelta class by adding some functions and properties that improve on the built-in ones. All right, so first let's make sure that the most current version of Pendulum is installed on your computer and in the terminal I'm going to go ahead and use pip to install it. So I'm going to go ahead and write pip install pendulum. Okay, and it looks like I've already got it, so to make sure that I've got everything I need, let's write pip show pendulum. And there in the output you can see the details of the installed library. So, let's go to the PYPI site and look up the page for this library and you can see I can just type into the Search box for Pendulum. I'll hit Return. All right, here's Pendulum right here. And I'll click that link. So here it takes me to a link to the library and we can see that this is a fairly popular library. Let's see, it's got 208 forks, so looks like it's gotten some use, and then if I look down here I've got a link to the documentation. So I'll go ahead and click that link. And you can see that brings me to the documentation for Pendulum, so if I scroll down a little bit you can see here's the Introduction and Instantiation and you can see that I'm scrolling down. This is quite a bit of documentation and features and up here you can see that there's an index to all the different features that Pendulum provides. Now, I'll let you read through the docs on your own time, but now that we have the library installed we can get started using it, which we're going to do in the rest of this chapter.

Contents