Skip to main content

python-libfaketime is a wrapper of libfaketime for python.

import datetime

from libfaketime import fake_time, reexec_if_needed

# libfaketime needs to be preloaded by the dynamic linker.
# This will exec the same command, but with the proper environment variables set.
# Or you can skip running this and manually manage your env (see get_reload_information()).
reexec_if_needed()

def get_tomorrow():
    return datetime.date.today() + datetime.timedelta(days=1)


@fake_time('2014-01-01 00:00:00')
def test_get_tomorrow():
    assert get_tomorrow() == datetime.date(2014, 1, 2)

It serves as a fast drop-in replacement for freezegun. Here’s the output of a totally unscientific benchmark on my laptop:

$ python benchmark.py
re-exec with libfaketime dependencies
timing 1000 executions of <class 'libfaketime.fake_time'>
0.021755 seconds

$ python benchmark.py freezegun
timing 1000 executions of <function freeze_time at 0x10aaa1140>
6.561472 seconds

Some brief details:

  • linux and osx

  • microsecond resolution

  • accepts datetimes and strings that can be parsed by dateutil

  • not threadsafe

  • will break profiling. A workaround: use libfaketime.{begin, end}_callback to disable/enable your profiler.

To install: pip install libfaketime.

Changelog

Semantic versioning is used.

0.1.1

released 2015-09-11

0.1.0

released 2015-06-23

  • add global start/stop callbacks

0.0.3

released 2015-03-28

  • initial packaged release

Metadata

Release files for libfaketime 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for libfaketime 0.1.1
File Size Uploaded Provenance Actions
libfaketime-0.1.1.tar.gz 36.9 kB Without provenance Details for libfaketime-0.1.1.tar.gz

Release files / libfaketime-0.1.1.tar.gz

Download URL libfaketime-0.1.1.tar.gz
Size 36.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c181a6a613799d3f263d77454a7ca7d61a6b3dd8275945b865b41e08c3c0f7a9
BLAKE2b-256 checksum
How to use checksums
61ce43bb56cde7773b7ab8197684c03b31a2295548f250c288e69c2f8b33c127
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for libfaketime 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page