Skip to main content

An IPython extension for compiling and using Fortran code interactively.

Project description

Fortran magic

PyPI CI PyPI - Downloads

Compile and import symbols from a cell with Fortran code, using f2py.

Attention: I am looking for collaborators to maintain this project. If you are interested, please open an issue (or PRs) with your proposals for improvements and volunteer to be a maintainer.

The contents of the cell are written to a .f90 file in the directory IPYTHONDIR/fortran using a filename with the hash of the code. This file is then compiled. The resulting module is imported and all of its symbols are injected into the user's namespace.

Install

You can install or upgrade via uv:

uv add fortran-magic

Or via pip:

pip install -U fortran-magic

Or run directly

uv run --with=fortran-magic ipython

Basic usage

Once it's installed, you can load it with %load_ext fortranmagic. Then put your Fortran code in a cell started with the cell magic %%fortran. For example:

In[1]: %load_ext fortranmagic

In[2]: %%fortran

       subroutine f1(x, y, z)
            real, intent(in) :: x,y
            real, intent(out) :: z

            z = sin(x+y)

       end subroutine f1

Every symbol is automatically imported. So the subroutine f1 is already available in your python session as a function:

In[3]:  f1(1.0, 2.1415)
Out[3]: 9.26574066397734e-05

Tests

Run tests with:

uv run --group dev pytest

See the documentation for further details.

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

fortran_magic-1.0.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fortran_magic-1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file fortran_magic-1.0.tar.gz.

File metadata

  • Download URL: fortran_magic-1.0.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fortran_magic-1.0.tar.gz
Algorithm Hash digest
SHA256 a34ef0a0bc535bd45c7afb7ba027f74b156bf0ed8abf5f7c11d01fe185591520
MD5 c1a726bcbca2b88cf631861ee7f5a955
BLAKE2b-256 c038e7a6bcba8d28c45cc3b0498bf0a0ea61ac27962a8214de1e123ded462843

See more details on using hashes here.

Provenance

The following attestation bundles were made for fortran_magic-1.0.tar.gz:

Publisher: release.yml on mgaitan/fortran_magic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fortran_magic-1.0-py3-none-any.whl.

File metadata

  • Download URL: fortran_magic-1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fortran_magic-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28aff14396b3afb470655e29c688c64c90dd478db749733ffa3f46bdacf37dc3
MD5 c28dc99daf5a16dab55aa48985b081f2
BLAKE2b-256 499424b8af11f5f7e6dc6c9ef7842bb773e82f466557d6efeacf891119104bba

See more details on using hashes here.

Provenance

The following attestation bundles were made for fortran_magic-1.0-py3-none-any.whl:

Publisher: release.yml on mgaitan/fortran_magic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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