Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Dates and Times in Python Where on Earth do Timezones Make Sense? Datetime Awareness

Justin Noor
Justin Noor
3,692 Points

Why are some python libraries written in C?

I've never understood why many Python libraries, such as the datetime library, are written in C. I thought Python is a language on its own. Can anyone shed some light on this?

For example if you go to the Python docs and look at the datetime library, and click on the source code at the top left, it will take you to the Mercurial/CPython library page. What is CPython?

Peter Lawless
Peter Lawless
24,402 Points

I've heard that Python is built on top of C.

2 Answers

Jacob Herrington
Jacob Herrington
15,835 Points

The most popular implementation of Python is CPython which is written in C - meaning that the interpreter is written in C. Therefore, if you are using CPython it is possible to add features to your Python code with C. In a manner of speaking, by writing C code you are able to extend CPython itself which allows you to do things like add a new kind of Object.

Here are the source files for CPython on GitHub. If you'd like to see what I mean.

If you are interested in other implementations of Python including a Java implementation and a mind boggling version of the Python interpreter written in Python itself, here is some documentation to introduce you to the concept.

Furthermore, if you'd like to use C with Python yourself, this might interest you.