Giter Site home page Giter Site logo

plecos's Introduction

banner

Plecos

Utility library to validate the Metadata of assets oceanprotocol.com

"๐ŸŒŠ Plecos are fish which mostly eat green surface algae and are excellent window cleaners."

photo

Hypostomus plecostomus, the suckermouth catfish or common pleco, ('hypo' = under, 'stoma' = mouth, 'pleco'= pleated) is a tropical fish belonging to the armored catfish family (Loricariidae), named for the armor-like longitudinal rows of scutes that cover the upper parts of the head and body. Hypostomus plecostomus is named for its sucker-like mouth, which allows it to adhere to a surface, as well as to hold and rasp at food. This omnivorous species feeds on algae, aquatic plants, and small crustaceans. -Wikipedia

๐Ÿฒ๐Ÿฆ‘ THERE BE DRAGONS AND SQUIDS. This is in alpha state and you can expect running into problems. If you run into them, please open up a new issue. ๐Ÿฆ‘๐Ÿฒ


Table of Contents


Features

Plecos contains functions that validate metadata formatted as json according to OEP-8. You can validate a single json containg metadata or a list with with multiple links which contain metadata.

Get Started

The following online tools are useful when working with JSON and schemas; https://www.jsonschema.net/ https://jsonlint.com/ http://jsonviewer.stack.hu/

Quickstart

After installing and importing the package, call the .is_valid_file(YOUR_JSON_PATH, JSON_SCHEMA_PATH) function to check a json file against the latest OEP8 schema.

from pathlib import Path
import plecos

# Check if valid, if not - list the error in a summary form
if not plecos.is_valid_file_local('metadata.json'):
    errors = plecos.list_errors_file('metadata.json')
if errors:
    for e in errors:
        print(e)    

A dictionary object can also be checked against the schema, using .is_valid_dict(python_dictionary).

import plecos
import json

# Load it into a dictionary
with open('metadata.json') as json_file:
    this_json_dict = json.load(json_file)
        
# Check if valid, if not - list the error in a summary form
if not plecos.is_valid_dict_local(this_json_dict):
    errors = plecos.list_errors_dict(this_json_dict)
if errors:
    for e in errors:
        print(e)

Summary of functions

Several convenience functions are defined for validated against "local" or "remote" metadata.

  • Wrapping jschema.Draft7Validator.validate()

    • validate_dict(json_dict, schema_path)
      • validate_dict_local(json_dict)
      • validate_dict_remote(json_dict)
    • validate_file(json_path, schema_path)
      • validate_file_local(json_path)
      • validate_file_remote(json_path)
  • Wrapping jschema.Draft7Validator.is_valid()

    • is_valid_dict(json_dict, schema_path)
      • is_valid_dict_local(json_dict)
      • is_valid_dict_remote(json_dict)
    • is_valid_file(json_path, schema_path)
      • is_valid_file_local(json_path)
      • is_valid_file_remote(json_path)
  • Wrapping jschema.Draft7Validator.iter_errors()

    • list_errors(json_dict, schema_path)
      • list_errors_dict_remote(json_dict)
      • list_errors_dict_remote(json_dict)
      • list_errors_file_local(json_path)
      • list_errors_file_remote(json_path)

list_errors returns a tuple containing a short summary of the error (the json path), and the full error object.

LOCAL_SCHEMA_FILE_ points to the latest OEP8 schema for local metadata. Older versions are included in the package.

REMOTE_SCHEMA_FILE_ points to the latest OEP8 schema for remote metadata. Older versions are included in the package.

LOCAL_SCHEMA_FILE and REMOTE_SCHEMA_FILE_ can be replaced with your own file path to your own schema.

License

Copyright 2018 Ocean Protocol Foundation Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

plecos's People

Contributors

marcusjones avatar malte18 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.