Skip to main content

f2py-jit

pypi version license Binder pipeline status coverage report

Just-in-time compilation of Fortran code in Python via f2py.

Check out the documentation for full details.

Quick start

Start from a piece of Fortran, say code.f90

subroutine hello()
  print*, "Hello world!"
end subroutine

Compile the code, import it and execute it

from f2py_jit import jit
f90 = jit('code.f90')
f90.hello()

Do the same but from a python string containing the source block

source = """
subroutine hello()
  print*, "Hello world!"
end subroutine
"""
f90 = jit(source)
f90.hello()

If the Fortran source contains multiple subroutines calling each other, f2py will not perform interprocedural optimizations (at least not by default). f2py_jit can inline the source code before compiling it, and you will get a performace boost [This feature is experimental]

f90 = jit('code.f90', inline=True)

Features

  • Compilation of Fortran source blocks as Python strings
  • Caching of module builds across executions
  • Support for Fortran derived types via f90wrap
  • Inlining to improve performance (experimental)

Dependencies

  • Fortran compiler (ex. gfortran)
  • numpy
  • meson (for Python >= 3.11)

The package currently supports Python versions from 3.7 to 3.14.

Important: on Debian-based OS, packages pkg-config and python3-dev are required with Python>=3.11. They must be installed at the OS level ex. via apt.

Note: Python versions >= 3.11 will use the meson backend to build Fortran extensions, which has slower build times than distutils (used by default in versions < 3.11).

Installation

From pip

pip install f2py-jit

To install the package with support for derived types (courtesy of f90wrap

pip install f2py-jit[types]

Note that this requires Python >= 3.8.

From source

git clone https://framagit.org/coslo/f2py-jit.git
cd f2py_jit
pip install .

Credits

Part of this code is adapted from numpy.f2py module by Pearu Peterson, in accordance with the NumPy license.

Authors

Daniele Coslovich: https://www.units.it/daniele.coslovich/

Release files for f2py-jit 1.2.2

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

Source distribution (sdist)

Source distribution for f2py-jit 1.2.2
File Size Uploaded
f2py_jit-1.2.2.tar.gz 29.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for f2py-jit 1.2.2
File Interpreter ABI Platform
f2py_jit-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 55.3 kB

Release files / f2py_jit-1.2.2.tar.gz

Download URL f2py_jit-1.2.2.tar.gz
Size 29.2 kB
Tags Source
SHA-256 checksum
How to use checksums
078851484137f1d65a7e58deb7be8eecf43a8c9f71f9142eb655d19006df0de2
BLAKE2b-256 checksum
How to use checksums
6f65025ebbe575496b9748a610e132fe7fb2e78bab7fb05bf355934ecb2514e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / f2py_jit-1.2.2-py3-none-any.whl

Download URL f2py_jit-1.2.2-py3-none-any.whl
Size 26.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b521250b544bc4f107361b66ef0f0e5ae7ae20e1177b43fe2d1524a28bd638a
BLAKE2b-256 checksum
How to use checksums
47accafad289134ceff4b340af9985b3afea885dcb60c7d76a59466114e8ebdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.11.0

1 release file

0.10.3

1 release file

0.10.2

1 release file

0.10.1

1 release file

0.10.0

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

0.8.5

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.3.1

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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