Python API

This page describes the Python API.

OFDSSchema

Before instantiating the other classes on this page, you first need to create an OFDSSchema object:

class libcoveofds.schema.OFDSSchema

Represents and provides information about the schema.

Example

from libcoveofds.schema import OFDSSchema

schema = OFDSSchema()

JSONSchemaValidator

class libcoveofds.jsonschemavalidate.JSONSchemaValidator(schema: OFDSSchema)

Validates data using the JSON Schema method

validate(json_data: dict) list

Call with data. Results are returned.

Returns:

class libcoveofds.jsonschemavalidate.ValidationError(json_schema_exceptions_validation_error: ValidationError, json_data: dict, schema: OFDSSchema)

Any problems found in data are returned as an instance of this class.

json()

Return representation of this error in JSON.

For more information, see handling validation errors in the jsonschema library documentation.

Example

from libcoveofds.schema import OFDSSchema
from libcoveofds.jsonschemavalidate import JSONSchemaValidator

schema = OFDSSchema()
worker = JSONSchemaValidator(schema)
data = {
    "networks": "many"
}
out = worker.validate(data)
print([i.json() for i in out])

PythonValidate

class libcoveofds.python_validate.PythonValidate(schema: OFDSSchema)

Validates data using additional checks custom written in Python

validate(json_data: dict) list

Call with data. Results are returned.

For more information on the checks and on the results format, see Checks.

Example

from libcoveofds.schema import OFDSSchema
from libcoveofds.python_validate import PythonValidate

schema = OFDSSchema()
worker = PythonValidate(schema)
data = {
    "networks": [
        {"id": "1", "nodes": [
            {"id": "1"}
        ]}
    ]
}
out = worker.validate(data)
print(out)

AdditionalFields

class libcoveofds.additionalfields.AdditionalFields(schema: OFDSSchema)

Process data and return additional fields information

process(json_data: dict) list

Process method. Call with data. Results are returned.

For more information on the results format, see Additional Fields.

Example

from libcoveofds.schema import OFDSSchema
from libcoveofds.additionalfields import AdditionalFields

schema = OFDSSchema()
worker = AdditionalFields(schema)
data = {
    "networks": [
        {"id": "1", "cat": "socks"}
    ]
}
out = worker.process(data)
print(out)

JSONToGeoJSONConverter

class libcoveofds.geojson.JSONToGeoJSONConverter

Converts JSON data to GeoJSON.

get_meta_json() dict

After processing, call to get meta information on the conversion.

get_nodes_geojson() dict

After processing, call to get nodes GeoJSON output.

get_spans_geojson() dict

After processing, call to get spans GeoJSON output.

process_package(package_data: dict) None

Process network package. Pass in data. Results are stored on object to get with other methods.

For more information on the input and output formats, see the JSON publication format reference and the GeoJSON publication format reference.

Example

from libcoveofds.geojson import JSONToGeoJSONConverter

worker = JSONToGeoJSONConverter()
data = {
        "networks": [
            {"id": "1", "nodes": [
                {"id": "1"}
            ]}
        ]
    }
worker.process_package(data)
print(worker.get_nodes_geojson())
print(worker.get_spans_geojson())
print(worker.get_meta_json())

GeoJSONToJSONConverter

class libcoveofds.geojson.GeoJSONToJSONConverter

Converts GeoJSON data to JSON.

get_json() dict

After processing, call to get JSON output.

get_meta_json() dict

After processing, call to get meta information on conversion.

process_data(data: dict, assumed_feature_type: GeoJSONAssumeFeatureType = GeoJSONAssumeFeatureType.NODE) None

Process data. Results are stored on object to get with other methods.

Can be called multiple times with as many GeoJSON files as needed.

For more information on the input and output formats, see the GeoJSON publication format reference and the JSON publication format reference.

Example

from libcoveofds.geojson import GeoJSONToJSONConverter

worker = GeoJSONToJSONConverter()
nodes_data = {
    'type': 'FeatureCollection',
    'features': [
        {'type': 'Feature', 'geometry': None, 'properties': {'id': '1', 'network': {'id': '1'}}}
     ]
}
spans_data = {
    'type': 'FeatureCollection',
    'features': []
}

worker.process_data(nodes_data, spans_data)
print(worker.get_json())
print(worker.get_meta_json())