A python client for retrieving Iglu schemas and validating self-describing JSON
Project description
Python client for Iglu
A Python client and resolver for [Iglu schema repositories][iglu-wiki]
Installation
pip install iglu_client
Usage
import json
import jsonschema
from iglu_client import SchemaResolver, SelfDescribingJson
resolver_conf = """
{
"schema": "iglu:com.snowplowanalytics.iglu/resolver-config/jsonschema/1-0-2",
"data": {
"cacheSize": 500,
"repositories": [
{
"name": "My Private Repo",
"priority": 0,
"vendorPrefixes": ["com.mycompany"],
"connection": {"http": {"uri": "http://myprivaterepo.com", "apikey": "api-key"}}
},
{
"name": "Iglu Central",
"priority": 1,
"vendorPrefixes": ["com.snowplowanalytics.snowplow"],
"connection": {"http": {"uri": "http://iglucentral.com"}}
}
]
}
}
"""
resolver = SchemaResolver.parse(resolver_conf)
# Retrieve a schema
schema = resolver.lookup_schema("iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0")
print("schema: %s" % schema)
# Validate a self-describing JSON
event = """
{
"schema": "iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0",
"data": {
"targetUrl": "https://mixpanel.com"
}
}
"""
data = SelfDescribingJson.parse(event)
try:
data.validate(resolver) # will throw an exception if the event is invalid
print("event is valid")
except jsonschema.exceptions.ValidationError as e:
print("event is invalid")
if data.valid(resolver): # will return True or False
print("event is valid")
else:
print("event is invalid")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
iglu-client-0.1.1.tar.gz
(7.9 kB
view details)
File details
Details for the file iglu-client-0.1.1.tar.gz
.
File metadata
- Download URL: iglu-client-0.1.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6adee36c74e59aee753c64e09a5e4bc0395538a4348d69f8508733e47f3836f |
|
MD5 | f339bb29afd10e858590fd9aaaff8bd0 |
|
BLAKE2b-256 | 9e6081349618d980bfb5d5af3a119d42a2284e972116b4a0e7efdb2a58823fe2 |