Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (
Help us improve Python packaging - Donate today!

A fast alternative to freezegun that wraps libfaketime.

Project Description

python-libfaketime is a wrapper of libfaketime for python. It serves as a fast drop-in replacement for freezegun.


Install with pip:

$ pip install libfaketime


Some brief details:

  • Works with Linux and OS X, Pythons 2 and 3.
  • Microsecond resolution.
  • Accepts datetimes and strings that can be parsed by dateutil.
  • Not threadsafe.
  • Breaks profiling. To workaround this, use libfaketime.{begin, end}_callback to disable/enable your profiler.


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.
# You can also skip this and manually manage your env (see "How to avoid re-exec").

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

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

By default, reexec_if_needed removes the LD_PRELOAD variable after the re-execution, to keep your environment as clean as possible. You might want it to stick around, for example when using parallelized tests that use subprocess like pytest-xdist. To keep them around, pass remove_vars=False like:


Benchmark against freezegun

Here’s the output of a totally unscientific benchmark on my laptop:

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

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

Use with py.test

It’s easiest to reexec from inside the pytest_configure hook:

from libfaketime import reexec_if_needed

def pytest_configure():

How to avoid re-exec

Sometimes, re-exec does unexpected things. You can avoid those problems by preloading libfaketime yourself. The environment variables you need can be found by running python-libfaketime on the command line:

$ python-libfaketime
export LD_PRELOAD="/home/foo/<snip>/vendor/libfaketime/src/"

You can use them as such:

$ eval $(python-libfaketime)
$ nosetests  # ...or any other code that imports libfaketime

Known Issues

It was found that calling uuid.uuid1() multiple times while in a fake_time context could result in a deadlock. This situation only occured for users with a system level uuid1 library. In order to combat this issue, python-libfaketime temporarily disables the system level library by patching _uuid_generate_time to None while in the fake_time context.


Semantic versioning is used.


released 2016-04-02

  • freezegun’s tick() is now supported; see their docs for usage.


released 2016-03-04

  • invoking libfaketime from the command line will now print the necessary environment to avoid a re-exec.


released 2016-03-01

  • python 3 support


released 2015-09-11


released 2015-06-23

  • add global start/stop callbacks


released 2015-03-28

  • initial packaged release

Release History

This version
History Node


History Node


History Node


History Node


Download Files

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

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(38.9 kB) Copy SHA256 Hash SHA256
Source Jul 26, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting