# Renaming datetime.datetime to datetime.DateTime

**URL:** <https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279>\
**Category:** Ideas\
**Created:** [April 27, 2023, 9:03pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279 "2023-04-27T21:03:32Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![pf\_moore](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pf_moore/32/35_2.png) [@pf\_moore](https://discuss.python.org/u/pf_moore)\
**Post date:** [May 8, 2023, 9:02am UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/41 "2023-05-08T09:02:51Z")

</div>

> [@ehomrich](#):
>
> There are modules with even more glaring inconsistencies - such as `logging` and `unittest` whose methods use camelCase - which became “facts of life”.

This is the key thing here. Simply changing `datetime` doesn’t make Python consistent, it simply changes (slightly) how much inconsistency there is. Given that fact, the change becomes little more than churn for no benefit.

FWIW, I tend to think of dates and times as “fundamental types” like lists and strings, and as such I’m quite happy with the lowercase names.

---

<div class="post-metadata">

**Author:** ![USSX-Hares](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ussx-hares/32/13471_2.png) [@USSX-Hares](https://discuss.python.org/u/USSX-Hares)\
**Post date:** [July 13, 2023, 11:53am UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/42 "2023-07-13T11:53:15Z")

</div>

> [@ehomrich](#):
>
> There are modules with even more glaring inconsistencies - such as `logging` and `unittest` whose methods use camelCase - which became “facts of life”.

I use Python since 3.5. Many modules were introduced since then. Many methods were marked as deprecated, even methods I’ve used before. And if, back in the days in 2016, I had seen the deprecation warning for the `logging.getLogger` or `datetime.datetime`, I would use the canonically named versions instead, despite the old answers from StackOverflow. It doesn’t matter how the old code is written, it does matter how the new code is written and how the newcomers are taught. Python is a great language not because it retained backwards-compatibility, but because of how consistent it is in its standards.

P.S.  
Even Grammarly plugin suggests me replacing `datetime` with the `DateTime`.

P.P.S.  
Let’s think not about our present, let’s think about Python’s future. And, in that future, we want it to be perfect.

---

<div class="post-metadata">

**Author:** ![ssweber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ssweber/32/9684_2.png) [@ssweber](https://discuss.python.org/u/ssweber)\
**Post date:** [July 13, 2023, 12:33pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/43 "2023-07-13T12:33:52Z")

</div>

+1 on `import datetime as dt`

I recently did that to the library I’m working on, and it reduced my own confusion

---

<div class="post-metadata">

**Author:** ![ssweber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ssweber/32/9684_2.png) [@ssweber](https://discuss.python.org/u/ssweber)\
**Post date:** [July 13, 2023, 2:21pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/44 "2023-07-13T14:21:11Z")

</div>

Per @hugovk suggestion, I’ll start working on a pull-request to make the required changes, eg:

```python
-from datetime import timedelta
-delta = timedelta(
+import datetime as dt
+delta = dt.timedelta(

```

In examples that use `dt` as a argument, I will rename to `dt_obj`:

```python
import datetime as dt

def dst(self, dt_obj: dt.datetime) -> dt.timedelta:
    # Code to set dston and dstoff to the time zone's DST
    # transition times based on the input dt_obj.year, and expressed
    # in standard local time.

    if dston <= dt_obj.replace(tzinfo=None) < dstoff:
        return dt.timedelta(hours=1)
    else:
        return dt.timedelta(0)

```

---

<div class="post-metadata">

**Author:** ![Rosuav](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rosuav/32/3429_2.png) [@Rosuav](https://discuss.python.org/u/Rosuav)\
**Post date:** [July 13, 2023, 2:23pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/45 "2023-07-13T14:23:21Z")

</div>

> [@ssweber](#):
>
> In examples that use `dt` as a argument, I will rename to `dt_obj`:

That feels a bit clunky, but I can’t at the moment think of anything that isn’t. Part of me wants to go with “ts” for timestamp, but that would cause other confusion.

---

<div class="post-metadata">

**Author:** ![ssweber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ssweber/32/9684_2.png) [@ssweber](https://discuss.python.org/u/ssweber)\
**Post date:** [July 13, 2023, 2:29pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/46 "2023-07-13T14:29:57Z")

</div>

Open to suggestions! Perhaps lose the \_, `dtobj`

---

<div class="post-metadata">

**Author:** ![hugovk](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/hugovk/32/14505_2.png) [@hugovk](https://discuss.python.org/u/hugovk)\
**Post date:** [July 13, 2023, 2:42pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/47 "2023-07-13T14:42:27Z")

</div>

`my_datetime` or `my_dt`? Some arbitrary [Monty Python name](https://docs.python.org/3/library/pprint.html#pprint.PrettyPrinter)?

---

<div class="post-metadata">

**Author:** ![Rosuav](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rosuav/32/3429_2.png) [@Rosuav](https://discuss.python.org/u/Rosuav)\
**Post date:** [July 13, 2023, 2:47pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/48 "2023-07-13T14:47:25Z")

</div>

I’m hesitating a bit with this one, but maybe `now` as a timestamp? As a function parameter, it’s not ideal (you could be asking about any point in time), but maybe not too bad, and certainly it’s unambiguous.

---

<div class="post-metadata">

**Author:** ![merwok](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/merwok/32/29_2.png) [@merwok](https://discuss.python.org/u/merwok)\
**Post date:** [July 13, 2023, 3:49pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/49 "2023-07-13T15:49:57Z")

</div>

Sorry but I don’t think there is a consensus for these changes.

There are groups that use conventional aliases (`import numpy as np`) but not the stdlib.

For object names, picking something related to the meaning or role is generally more interesting and useful than based on type. `dt_obj` is clumsy, but `start_date` for example is enlightening.

---

<div class="post-metadata">

**Author:** ![ssweber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ssweber/32/9684_2.png) [@ssweber](https://discuss.python.org/u/ssweber)\
**Post date:** [July 13, 2023, 3:54pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/50 "2023-07-13T15:54:01Z")

</div>

Since it’s used alot, how about just `d`. It’s already that way at the top of the documentation:

> A [`datetime`](https://docs.python.org/3.12/library/datetime.html#datetime.datetime) object _d_ is aware if both of the following hold:
> 
> 1. `d.tzinfo` is not `None`
> 2. `d.tzinfo.utcoffset(d)` does not return `None`
> 
> Otherwise, _d_ is naive.

I would replace dt → d, and where other examples are already using `d` (or dt): use:

- `dt = time(hour=12, minute=34, second=56, microsecond=0)` → `t = time(hour=12, minute=34, second=56, microsecond=0)` (which aligns with how it uses \*t\* a little lower anyway.
- `d = timedelta(microseconds=-1)` → `td = dt.timedelta(microseconds=-1)`
- `d = date(2002, 12, 31)` → `dd = dt.date(2002, 12, 31)`

---

<div class="post-metadata">

**Author:** ![ssweber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ssweber/32/9684_2.png) [@ssweber](https://discuss.python.org/u/ssweber)\
**Post date:** [July 13, 2023, 4:21pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/51 "2023-07-13T16:21:52Z")

</div>

> [@merwok](#):
>
> Sorry but I don’t think there is a consensus for these changes.

That’s fair. Changing it to `import datetime as dt` throughout the datetime docs would be a significant change.

Edit:  
Do you think there is consensus for a small note making users aware of the `import datetime as dt` convention, and to perhaps avoid using “dt” as an object name?

Something like:

> In this documentation, the name _dt_ is consistently used to represent a datetime object. However, it is important to note that in many libraries the datetime module itself is commonly imported as `dt`, for example, `import datetime as dt`

---

<div class="post-metadata">

**Author:** ![storchaka](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/storchaka/32/217_2.png) [@storchaka](https://discuss.python.org/u/storchaka)\
**Post date:** [July 14, 2023, 7:43am UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/52 "2023-07-14T07:43:32Z")

</div>

I often use `dt` as a name of a local variable or parameter of `datetime` type, but never used `import datetime as dt`. If I need a short name for the `datetime` module, I would rather write `import datetime as DT`.

---

<div class="post-metadata">

**Author:** ![petersuter](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@petersuter](https://discuss.python.org/u/petersuter)\
**Post date:** [July 14, 2023, 8:01am UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/53 "2023-07-14T08:01:42Z")

</div>

`import datetime as dtmod` is also an option: [GitHub search](https://github.com/search?q=%22datetime+as+dtmod%22&type=code)

---

<div class="post-metadata">

**Author:** ![flyinghyrax](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/flyinghyrax/32/12394_2.png) [@flyinghyrax](https://discuss.python.org/u/flyinghyrax)\
**Post date:** [July 15, 2023, 7:35pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/54 "2023-07-15T19:35:01Z")

</div>

For whatever it’s worth, I tend to only import the `datetime` _class_:

```python
from datetime import datetime, timedelta, timezone, ...

```

There are very few module-level constants in the `datetime` module and my most commonly used classes are `datetime.datetime` and `datetime.timedelta` so I only import those. \[1\]

And if I’m feeling adventurous that day I might alias them at that point:

```python
from datetime import datetime as DateTime

```

But its been quite a while since I’ve imported the whole module at all. Everything I’ve needed is present as a method or classmethod on `datetime`-the-class.

* * *

1. This has the handy side effect of making them niceto use in type annotations:

---

<div class="post-metadata">

**Author:** ![ssweber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ssweber/32/9684_2.png) [@ssweber](https://discuss.python.org/u/ssweber)\
**Post date:** [July 16, 2023, 1:42pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/55 "2023-07-16T13:42:52Z")

</div>

The replies have been enlightening.

I got curious to see how prevalent each import convention is:

GitHub code search (excluding forks):

- `from datetime import ...` - 1.2m files
- `import datetime as dt` - 79.4k files
- `from datetime import datetime as dt` - 20.9k files
- `import datetime as dtmod` - 14 files

---

<div class="post-metadata">

**Author:** ![EpicWink](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/epicwink/32/17968_2.png) [@EpicWink](https://discuss.python.org/u/EpicWink)\
**Post date:** [July 16, 2023, 8:30pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/56 "2023-07-16T20:30:24Z")

</div>

What about plain old `import datetime` (perhaps you need regex for end-of-line `$`, or comma `,`)

---

<div class="post-metadata">

**Author:** ![ssweber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ssweber/32/9684_2.png) [@ssweber](https://discuss.python.org/u/ssweber)\
**Post date:** [July 16, 2023, 9:30pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/57 "2023-07-16T21:30:50Z")

</div>

770k

[/^import datetime$/ NOT is:fork](https://github.com/search?q=%2F%5Eimport+datetime%24%2F+NOT+is%3Afork&type=code)

---

<div class="post-metadata">

**Author:** ![gwerbin](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@gwerbin](https://discuss.python.org/u/gwerbin)\
**Post date:** [August 3, 2023, 11:16am UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/58 "2023-08-03T11:16:45Z")

</div>

I _exclusively_ use `from datetime import datetime as Datetime, timedelta as Timedelta, timezone as Timezone`. The fact that my coworkers adopted it without complaint or hesitation suggests to me that it’s a good idea to add these as aliases in the standard library. It seems rather silly to push back hard against adding these as _aliases_ (not renaming them, literally just aliases) while we have sweeping syntax changes entering the language at every new version now.

---

<div class="post-metadata">

**Author:** ![gymate](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/gymate/32/16924_2.png) [@gymate](https://discuss.python.org/u/gymate)\
**Post date:** [April 19, 2025, 4:47pm UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/59 "2025-04-19T16:47:36Z")

</div>

Just throwing my two cents to the discussion:

I get that consistency is a priority, but I ran into mixing up `datetime` and `datetime.datetime` so many times… (See an example [here](https://github.com/python/cpython/issues/49780#issuecomment-2507877664).)

As type hints were introduced in [PEP 484](https://peps.python.org/484), people are writing down object types more than ever. After reading through the whole discussion, I still think that a long-term (as @boxed mentioned, even a 100 year-long) plan is needed to rename ambiguous classes—even if they conform to PEP 8 due to [this clause](https://peps.python.org/pep-0008/#:~:text=In%20particular:%20do%20not%20break%20backwards%20compatibility%20just%20to%20comply%20with%20this%20PEP). It would help future (mostly beginner) developers so much!

---

<div class="post-metadata">

**Author:** ![blhsing](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/blhsing/32/25812_2.png) [@blhsing](https://discuss.python.org/u/blhsing)\
**Post date:** [April 21, 2025, 2:08am UTC](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279/60 "2025-04-21T02:08:15Z")

</div>

> [@PythonCHB](#):
>
> I do like the `import datetime as dt` idiom – is there anywhere else in the stdlib where that’s recommended? It’s very common idiom in the scipy world:
> 
> ```python
> import numpy as np
> import panda as pd
> import matplotlib.pyplot as plt
> ...
> 
> ```

In Python 3.14’s UUID docs (but not in 3.13) there’s now an [example](https://docs.python.org/3.14/library/uuid.html#example) using the convention:

```python
>>> # get UUIDv7 creation (local) time as a datetime object
>>> import datetime as dt
>>> dt.datetime.fromtimestamp(u.time / 1000)
datetime.datetime(...)

```

In the `multiprocessing` docs there’s this [example](https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods):

```python
import multiprocessing as mp

def foo(q):
    q.put('hello')

if __name__ == ' __main__':
    mp.set_start_method('spawn')
    q = mp.Queue()
    p = mp.Process(target=foo, args=(q,))
    p.start()
    print(q.get())
    p.join()

```

In the `xml.etree.ElementTree` [docs](https://docs.python.org/3/library/xml.etree.elementtree.html):

```python
import xml.etree.ElementTree as ET
tree = ET.parse('country_data.xml')
root = tree.getroot()

```

In the `tkinter` [docs](https://docs.python.org/3/library/tkinter.html#coupling-widget-variables):

```python
import tkinter as tk

class App(tk.Frame):
    ...

```

And I could swear I’ve seen `import traceback as tb` somewhere in either the official docs or the CPython codebase before, but nope I can’t find it now, though it’s most certainly a widely used convention as well.

[Previous page](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279.md?page=2)

[Next page](https://discuss.python.org/t/renaming-datetime-datetime-to-datetime-datetime/26279.md?page=4)
