Generating FloPy classes

MODFLOW 6 input continues to evolve as new models, packages, and options are developed, updated, and supported. All MODFLOW 6 input is described by DFN (definition) files, which are simple text files that describe the blocks and keywords in each input file. These definition files are used to build the input and output guide for MODFLOW 6. These definition files are also used to automatically generate FloPy classes for creating, reading and writing MODFLOW 6 models, packages, and options. FloPy and MODFLOW 6 are kept in sync by these DFN (definition) files, and therefore, it may be necessary for a user to update FloPy using a custom set of definition files, or a set of definition files from a previous release.

The FloPy classes for MODFLOW 6 are largely generated by a utility which converts DFN files in a modflow6 repository on GitHub or on the local machine into Python source files in your local FloPy install. For instance (output much abbreviated):

$ python -m flopy.mf6.utils.generate_classes

Updating the flopy MODFLOW 6 classes
  Updating the MODFLOW 6 classes using MODFLOW-USGS/modflow6/master
  Downloading MODFLOW 6 repository from
   file size: 15,821,180 bytes

total download time: 0.88 seconds
Uncompressing: C:\Users\***\AppData\Local\Temp\***\
Deleting zipfile C:\Users\***\AppData\Local\Temp\***\
Done downloading and extracting to C:\Users\***\AppData\Local\Temp\***
  Backup existing definition files in: C:\Users\***\flopy\flopy\mf6\data\dfn
  Replacing existing definition files with new ones.
  Deleting existing mf6 classes.
  Create mf6 classes using the downloaded definition files.
LIST OF FILES IN C:\Users\***\flopy\flopy\mf6\modflow
        1 -
        2 -

Similar functionality is available within Python, e.g.:

>>> from flopy.mf6.utils import generate_classes
>>> generate_classes()

The generate_classes() function has several optional parameters.

$ python -m flopy.mf6.utils.generate_classes -h
usage: [-h] [--owner OWNER] [--repo REPO] [--ref REF]
                           [--dfnpath DFNPATH] [--no-backup]

Generate the MODFLOW 6 flopy classes using definition files from the MODFLOW 6
GitHub repository or a set of definition files in a folder provided by the

  -h, --help         show this help message and exit
  --owner OWNER      GitHub repository owner; default is 'MODFLOW-USGS'.
  --repo REPO        Name of GitHub repository; default is 'modflow6'.
  --ref REF          Branch name, tag, or commit hash to use to update the
                     definition; default is 'master'.
  --dfnpath DFNPATH  Path to a definition file folder that will be used to
                     generate the MODFLOW 6 classes.
  --no-backup        Set to disable backup. Default behavior is to keep a
                     backup of the definition files in dfn_backup with a date
                     and timestamp from when the definition files were

For example, use the develop branch instead:

$ python -m flopy.mf6.utils.generate_classes --ref develop

use a fork of modflow6:

$ python -m flopy.mf6.utils.generate_classes --owner your-username --ref your-branch

maybe your fork has a different name:

$ python -m flopy.mf6.utils.generate_classes --owner your-username --repo your-modflow6 --ref your-branch

local copy of the repo:

$ python -m flopy.mf6.utils.generate_classes --dfnpath ../your/dfn/path

Branch names, commit hashes, or tags may be provided to ref.

By default, a backup is made of FloPy’s package classes before rewriting them. To disable backups, use --no-backup from command-line, or backup=False with the Python function.

Testing class generation

Tests for the generate_classes() utility are located in The tests depend on virtualenv and will be skipped if run in parallel without the --dist loadfile option for pytest-xdist.