Skip to content

Replace datetime.utcnow() with datetime.now(datetime.UTC) to prevent deprecation warnings in Python 3.12+ #55

Open
@dasycarpum

Description

@dasycarpum

Description

In Python 3.12+, the use of datetime.datetime.utcnow() is deprecated and scheduled for removal in future versions. The recommended approach is to use datetime.datetime.now(datetime.UTC) for timezone-aware UTC timestamps.

In findatapy/market/marketdatarequest.py, the following line currently raises a DeprecationWarning during test runs:

start_date="year", finish_date=datetime.datetime.utcnow()

Suggested Fix

To ensure compatibility with future versions of Python and avoid runtime warnings, please replace:
datetime.datetime.utcnow()
with
datetime.datetime.now(datetime.UTC)

This change is safe and aligns with the latest best practices for timezone-aware datetime handling in Python.

Environment :

Python version: 3.12.3
Library version: 0.1.40
Platform: Linux Ubuntu 24.04

Thanks

Thank you for maintaining this package! I'd be happy to submit a PR if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions