pyKML Modules

The pyKML library is separated into several modules, based on similar functionality.


pyKML Factory Module

The pykml.factory module provides objects and functions that can be used to create KML documents element-by-element. The factory module leverages lxml’s ElementMaker factory objects to create KML objects with the appropriate namespace prefixes.


Returns the correct factory object for a given namespace


Generates a python script that will construct a given KML document


pyKML Parser Module

The pykml.parser module provides functions that can be used to parse KML from a file or remote URL.

class pykml.parser.Schema(schema)[source]

A class representing an XML Schema used to validate KML documents


Asserts that a KML document is valide

The method generates a validation error if the document is not valid when compared to the XML Schema.


Validates a KML document

This method eturns a boolean value indicating whether the KML document is valid when compared to the XML Schema.

pykml.parser.fromstring(text, schema=None)[source]

Parses a KML text string

This function parses a KML text string and optionally validates it against a provided schema object

pykml.parser.parse(fileobject, schema=None)[source]

Parses a file object

This functon parses a KML file object, and optionally validates it against a provided schema.


pyKML Helpers Module

The pykml.helpers module contains ‘helper’ functions that operate on pyKML document objects for accomplishing common tasks.


Separates the namespace from the element

pykml.helpers.set_max_decimal_places(doc, max_decimals)[source]

Sets the maximum number of decimal places used by KML elements

This method facilitates reducing the file size of a KML document.


pyKML Utility Module

The pykml.utility module provides utility functions that operate on KML documents


Counts the number of times each element is used in a document

Table Of Contents

Previous topic

Misc Examples

This Page