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!

Python powered Fortran preprocessor

Project Description

Fypp is a Python powered Fortran preprocessor. It extends Fortran with condititional compiling and template metaprogramming capabilities. Instead of introducing its own expression syntax, it uses Python expressions in its preprocessor directives, offering the consistency and flexibility of Python when formulating metaprogramming tasks. It puts strong emphasis on robustness and on neat integration into Fortran developing toolchains.

The project is hosted on bitbucket.

Detailed DOCUMENTATION is available on

Fypp is released under the BSD 2-clause license.

Main features

  • Definition and evaluation of preprocessor variables:

    #:if DEBUG > 0
      print *, "Some debug information"
    #:setvar LOGLEVEL 2
  • Macro defintions and macro calls (apart of minor syntax differences similar to scoped intelligent Fortran macros, which probably will be once part of the Fortran standard):

    #:def assertTrue(cond)
    if (.not. ${cond}$) then
      print *, "Assert failed in file ${_FILE_}$, line ${_LINE_}$"
      error stop
    end if
    $:assertTrue('size(myArray) > 0')
  • Conditional output:

    program test
    #:if defined('WITH_MPI')
      use mpi
    #:elif defined('WITH_OPENMP')
      use openmp
      use serial
  • Iterated output:

    interface myfunc
    #:for dtype in [ 'real', 'dreal', 'complex', 'dcomplex' ]
      module procedure myfunc_${dtype}$
    end interface myfunc
  • Inline directives:

    logical, parameter :: hasMpi = #{if defined('MPI')}#.true.#{else}#.false.#{endif}#
  • Insertion of arbitrary Python eval-expressions:

    character(*), parameter :: comp_date = "${time.strftime('%Y-%m-%d')}$"
  • Inclusion of files during preprocessing:

    #:include "macrodefs.fypp"
  • Using Fortran-style continutation lines in preprocessor directives:

    #:if var1 > var2 &
        & or var2 > var4
      print *, "Doing something here"
  • Passing multiline arguments to macros:

    #:def debug_code(code)
      #:if DEBUG > 0
    #:call debug_code
      if (size(array) > 100) then
        print *, "DEBUG: spuriously large array"
      end if
  • Preprocessor comments:

    #! This will not show up in the output
    #! Also the newline characters at the end of the lines will be suppressed
  • Suppressing the preprocessor output in selected regions:

    #! Definitions are read, but no output (e.g. newlines) will be produced
    #:include "macrodefs.fypp"


The command line tool is a single stand-alone script. You can run it directly from the source folder


or after copying it from the bin folder to any location listed in your PATH environment variable, by just issuing


Fypp needs a working Python interpreter either with version 2.7 or with version 3.2 or above.


The Fypp command line tool reads a file, preprocesses it and writes it to another file, so you would typically invoke it like:

fypp source.fypp source.f90

which would process source.fypp and write the result to source.f90. If input and output files are not specified, information is read from stdin and written to stdout.

The behavior of Fypp can be influenced with various command line options. A summary of all command line options can be obtained by:

fypp -h

Release History

This version
History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(23.4 kB) Copy SHA256 Hash SHA256
Source None Mar 8, 2016

Supported By

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 Google Google Cloud Servers DreamHost DreamHost Log Hosting