Skip to content

Python

Python API documentation for the cql2 package. Install from PyPI:

pip install cql2

API

cql2.Expr(cql2)

A CQL2 expression.

The cql2 can either be a cql2-text string, a cql2-json string, or a cql2-json dictionary.

Parameters:

  • cql2 (str | dict[str, Any]) –

    The input CQL2

Examples:

>>> from cql2 import Expr
>>> expr = Expr("landsat:scene_id = 'LC82030282019133LGN00'")
>>> expr = Expr({"op":"=","args":[{"property":"landsat:scene_id"},"LC82030282019133LGN00"]})

from_path(path) staticmethod

Reads CQL2 from a filesystem path.

Parameters:

  • path (PathLike) –

    The input path

Returns:

  • Expr ( Expr ) –

    The CQL2 expression

Examples:

>>> from cql2 import Expr
>>> expr = Expr.from_path("fixtures/text/example01.txt")

to_json()

Converts this cql2 expression to a cql2-json dictionary.

Returns:

  • dict[str, Any]

    dict[str, Any]: The cql2-json

Examples:

>>> from cql2 import Expr
>>> expr = Expr("landsat:scene_id = 'LC82030282019133LGN00'")
>>> expr.to_json()
{'op': '=', 'args': [{'property': 'landsat:scene_id'}, 'LC82030282019133LGN00']}

to_sql()

Converts this cql2 expression to a SQL query.

Returns:

  • SqlQuery ( SqlQuery ) –

    The SQL query and parameters

Examples:

>>> from cql2 import Expr
>>> expr = Expr("landsat:scene_id = 'LC82030282019133LGN00'")
>>> q.query
'("landsat:scene_id" = $1)'
>>> q.params
['LC82030282019133LGN00']

to_text()

Converts this cql2 expression to cql2-text.

Returns:

  • str ( str ) –

    The cql2-text

Examples:

>>> from cql2 import Expr
>>> expr = Expr({"op":"=","args":[{"property":"landsat:scene_id"},"LC82030282019133LGN00"]})
>>> expr.to_text()
'("landsat:scene_id" = 'LC82030282019133LGN00')'

cql2.SqlQuery

A SQL query

params: list[str] instance-attribute

The parameters, to use for binding.

query: str instance-attribute

The query, with parameterized fields.