Skip to main content
https://travis-ci.org/mapbox/cligj.svg https://coveralls.io/repos/mapbox/cligj/badge.png?branch=master

Common arguments and options for GeoJSON processing commands, using Click.

Example

Here’s an example of a command that writes out GeoJSON features as a collection or, optionally, a sequence of individual features. Since most software that reads and writes GeoJSON expects a text containing a single feature collection, that’s the default, and a LF-delimited sequence of texts containing one GeoJSON feature each is a feature that is turned on using the --sequence option. To write sequences of feature texts that conform to the JSON Text Sequences proposed standard (and might contain pretty-printed JSON) with the ASCII Record Separator (0x1e) as a delimiter, use the --rs option

import click
import cligj
import json

@click.command()
@cligj.sequence_opt
@cligj.use_rs_opt
def features(sequence, use_rs):
    features = [
        {'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]
    if sequence:
        for feature in features:
            if use_rs:
                click.echo(b'\x1e', nl=False)
            click.echo(json.dumps(feature))
    else:
        click.echo(json.dumps(
            {'type': 'FeatureCollection', 'features': features}))

On the command line it works like this.

$ features
{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'id': '1'}, {'type': 'Feature', 'id': '2'}]}

$ features --sequence
{'type': 'Feature', 'id': '1'}
{'type': 'Feature', 'id': '2'}

$ features --sequence --rs
^^{'type': 'Feature', 'id': '1'}
^^{'type': 'Feature', 'id': '2'}

In this example, ^^ represents 0x1e.

Plugins

cligj can also facilitate loading external click-based plugins via setuptools entry points. The cligj.plugins module contains a special group() decorator that behaves exactly like click.group() except that it offers the opportunity load plugins and attach them to the group as it is istantiated.

from pkg_resources import iter_entry_points

import cligj.plugins
import click

@cligj.plugins.group(plugins=iter_entry_points('module.entry_points'))
def cli():

    """A CLI application."""

    pass

@cli.command()
@click.argument('arg')
def printer(arg):

    """Print arg."""

    click.echo(arg)

@cli.group(plugins=iter_entry_points('other_module.more_plugins'))
def plugins():

    """A sub-group that contains plugins from a different module."""
    pass

Metadata

Release files for cligj 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cligj 0.3.0
File Size Uploaded
cligj-0.3.0.tar.gz 5.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for cligj 0.3.0
File Interpreter ABI Platform
cligj-0.3.0-py3-none-any.whl Python 3 none any Details
cligj-0.3.0-py2-none-any.whl Python 2 none any Details

Total release size: 22.3 kB

Release files / cligj-0.3.0.tar.gz

Download URL cligj-0.3.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a534cb32a44b7d1182c13fa81507b479cabbdbcb40f6470a080b670a88aff425
BLAKE2b-256 checksum
How to use checksums
e8dc3fcb0af2fbeacd384ab18b2c3a591e9a861c8018fd8ee793bfb0accfb8a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cligj-0.3.0-py3-none-any.whl

Download URL cligj-0.3.0-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dec88b7f2e7d4c133a3633e791575f07a4c5425e25817fa5e02a4b3f62133c7e
BLAKE2b-256 checksum
How to use checksums
ed4cc18480b8605df690d0b07d884a5e7be547bdad476e6117c69d64bacdfc56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cligj-0.3.0-py2-none-any.whl

Download URL cligj-0.3.0-py2-none-any.whl
Size 8.3 kB
Tags Python 2
SHA-256 checksum
How to use checksums
bc009db09177b132a4b789ca1dc12c65ee21b2c998af3f65fc1fae27a9343bd9
BLAKE2b-256 checksum
How to use checksums
dd98c272fd34654ceab24c27b804cfc1fc99b1a43dd0d4e56156130d2e7b8cd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.7.2

2 release files

0.7.1

2 release files

0.7.0

3 release files

0.6.0

3 release files

0.5.0

3 release files

0.4.0

3 release files

This release

0.3.0 This release

3 release files

0.2.0

3 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page