This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Farthing will run arbitrary Python code while tracing the argument and return types of all functions within a given file or directory. Farthing can then automatically add type annotations based on the types of the values it saw during the execution run. This might be useful if you want to add static types to existing Python code, or for exploring codebases where you’re not sure what type a value has.

For instance, the following code:

def factorial(n):
    result = 1

    for i in range(2, n + 1):
        result *= i

    return result

can be automatically transformed into:

def factorial(n: int) -> int:
    result = 1

    for i in range(2, n + 1):
        result *= i

    return result

by running Farthing against the following test file:

from import assert_equal

import fact

def test_fib():
    test_cases = [
        (0, 1),
        (1, 1),
        (2, 2),
        (3, 6),
        (4, 24),
        (5, 120),

    for index, value in test_cases:
        yield _check_fact, index, value

def _check_fact(index, value):
    assert_equal(value, fact.factorial(index))


Farthing can be called from the command line. The first argument should be the file or directory that should have type annotations added to it. The other arguments should be the Python script to run with any arguments. For instance:

farthing demo/ _virtualenv/bin/nosetests demo/


To run the demo, you can just run To explain what it actually does:

  1. Run make bootstrap to set up the virtualenv with dependencies.
  2. Run . _virtualenv/bin/activate to enter the virtualenv.
  3. Run farthing demo/ _virtualenv/bin/nosetests demo/ to run _virtualenv/bin/nosetests demo/ and add annotations to demo/ based on the types of actual values used in the execution run.


At the moment, Farthing is just a quick prototype, so currently has the following limitations:

  • Annotations are added just using the name of the type, which may not be available in the current scope.
  • Type annotations cannot be added to the Python script being run.
  • The first type seen is used, rather than any attempt at finding a super-type.

I’d be interested to see any projects along similar lines, so if you know of any, I’d be grateful if you let me know.

Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development 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