GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GRASS Python Scripting Library

by GRASS Development Team (


The code in lib/python/ provides grass.script in order to support GRASS scripts written in Python. The scripts/ directory of GRASS 7 contains a series of examples actually provided to the end users.

See code in:

Table of content

GRASS scripting tasks for Python provided by "grass.script"

The statement

import grass.script as grass

imports,, and modules.

To import only selected module

from grass.script import core as grass

Sample script (See the GRASS Wiki at for more examples)

#!/usr/bin/env python
#% description: Checks if vector map is 3D
#% keywords: vector
#% key: map
#% type: string
#% gisprompt: old,vector,vector
#% key_desc: name
#% description: Name of vector map
#% required: yes
import sys
import grass.script as grass
def main():
info = grass.parse_command('',
flags = 't',
map = options['map'])
if info['map3d'] == '1':
print 'Vector map is 3D'
print 'Vector map is 2D'
if __name__ == "__main__":
options, flags = grass.parser()

List of modules


GRASS-oriented interface to subprocess module

Interface to g.message

These all run g.message, differing only in which flag (if any) is used. fatal() is error(), but also calls sys.exit(1).

Interface to g.parser

Interface to g.parser, intended to be run from the top-level, e.g.

if __name__ == "__main__":
options, flags = grass.parser()

Interface to g.tempfile

Returns the name of a temporary file, created with g.tempfile.

Key-value parsers

Interface to g.gisenv

Interface to g.region

Interface to g.findfile

Interface to g.list

Interface to g.mapsets

Interface to g.version

Color parsing

Check GRASS environment variables

Create new GRASS location

Various utilities, not specific to GRASS


Interface for db.* modules.

from grass.script import db as grass


Interface for r.* modules.

from grass.script import raster as grass


Interface for v.* modules.

from grass.script import vector as grass


from grass.script import setup as gsetup


from grass.script import array as garray


Glynn Clements

Martin Landa <landa.martin>