Skip to main content

A fast alternative to freezegun that wraps libfaketime.

Project description

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

To install: pip install libfaketime.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libfaketime-0.1.0.tar.gz (36.3 kB view details)

Uploaded Source

File details

Details for the file libfaketime-0.1.0.tar.gz.

File metadata

  • Download URL: libfaketime-0.1.0.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for libfaketime-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ab422fa5d814503bf69e3fdbb4ba7322e8ef5ae95bff7c0b085fea521e4dfe1e
MD5 f9b0fff478fac1271d120d56b6c1bd5a
BLAKE2b-256 bee164529ac4c404540ce4b997dd792cd24c04bee88d496488fb6b4b43b2cde1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page