A pure Python parser for working with MapServer MapFiles, built using Lark. mappyfile is an official OSGeo Community Project.
mappyfile is used for formatting and validation in https://app.mapserverstudio.net/, and can be tested for free on any of your Mapfiles. If you find mappyfile useful please consider signing up for a professional account at https://mapserverstudio.net/. This will help to fund maintenance and further development of both mappyfile and MapServer.
Requirements
Python 3.8 or higher
Installation
mappyfile is available on PyPI (the Python Package Index), and can be installed using pip:
pip install mappyfile
This will also install its required dependencies - Lark, and jsonschema.
To install the optional lark-cython library for better performance on CPython you can run the following command:
pip install mappyfile[lark_cython]
pip install mappyfile[lark_cython,yaml]
mappyfile is also available on conda. Install as follows:
conda install -c conda-forge mappyfile
Documentation
Full documentation is available at http://mappyfile.readthedocs.io/en/latest/
Usage
From within Python scripts:
import mappyfile
mapfile = mappyfile.open("./docs/examples/raster.map")
# update the map name
mapfile["name"] = "MyNewMap"
new_layer_string = """
LAYER
NAME 'land'
TYPE POLYGON
DATA '../data/vector/naturalearth/ne_110m_land'
CLASS
STYLE
COLOR 107 208 107
OUTLINECOLOR 2 2 2
WIDTH 1
END
END
END
"""
layers = mapfile["layers"]
new_layer = mappyfile.loads(new_layer_string)
layers.insert(0, new_layer) # insert the new layer at any index in the Mapfile
for l in layers:
print("{} {}".format(l["name"], l["type"]))
print(mappyfile.dumps(mapfile, indent=1, spacer="\t"))
YAML support is available as an optional extra (pip install mappyfile[yaml]):
import mappyfile
import mappyfile.yaml
mapfile = mappyfile.open("./docs/examples/raster.map")
# export to YAML
mappyfile.yaml.save(mapfile, "raster.yaml")
# load back from YAML
mapfile2 = mappyfile.yaml.open("raster.yaml")
print(mappyfile.dumps(mapfile2))
Command line tools are also available - format, validate, schema, yaml-export, and yaml-import:
mappyfile format raster.map formatted_raster.map
mappyfile validate D:\ms-ogc-workshop\ms4w\apps\ms-ogc-workshop\**\*.map
mappyfile schema mapfile-schema-8-0.json --version=8.0
mappyfile yaml-export raster.map raster.yaml
mappyfile yaml-import raster.yaml raster.map
Contributors
Julien Enselme @jenselme
Loïc Gasser @loicgasser
Ian Turton @ianturton
TC Haddad @tchaddad (Conda support)
Metadata
Release files for mappyfile 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mappyfile-1.2.0.tar.gz | 114.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mappyfile-1.2.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 180.1 kB
Release files / mappyfile-1.2.0.tar.gz
| Download URL | mappyfile-1.2.0.tar.gz |
|---|---|
| Size | 114.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62698b7c4d10662948912f9466ea2cfa4ddf94038a20a7cd91e00e40641d7bb9
|
|
BLAKE2b-256 checksum How to use checksums |
b965e3c10b5f2fbd6b9b46c89feb39cf01f13dcb099ffad80fca38cc3b5054a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / mappyfile-1.2.0-py2.py3-none-any.whl
| Download URL | mappyfile-1.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 65.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0b875a35035f6fc712b153b134de27bdcbb42f732a5a05801c9bead7a123fa72
|
|
BLAKE2b-256 checksum How to use checksums |
4de22b8bd1befdec49b11e356d827ed0c97b34704816f7a04410efedac2744b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|