Install & Compatibility
Where this runs
tested against v0.1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.3MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 2.6s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Schema
✓ from apitools.jsonschema import Schema
validate
✓ from apitools.jsonschema import validate
Dataproxy
✓ from apitools.dataproxy import Dataproxy
Client
✓ from apitools.client import Client
This example demonstrates defining a JSON schema, validating data against it using `apitools.jsonschema.validate`, and using `apitools.dataproxy.Dataproxy` for schema-aware access and validation when modifying data.
from apitools.jsonschema import Schema, validate
from apitools.dataproxy import Dataproxy
# Define a simple JSON schema
my_schema = Schema({
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer", "minimum": 0}
},
"required": ["name", "age"]
})
# Validate data against the schema
valid_data = {"name": "Alice", "age": 30}
invalid_data = {"name": "Bob", "age": -5} # age cannot be negative
try:
validate(valid_data, my_schema)
print("Valid data:", valid_data)
except Exception as e:
print("Validation error for valid_data (should not happen):", e)
try:
validate(invalid_data, my_schema)
print("Validation attempt for invalid_data:", invalid_data)
except Exception as e:
print("Validation error for invalid_data (expected):", e)
# Expected: -5 is less than the minimum of 0
# Using Dataproxy for schema-aware data access
proxy_data = Dataproxy(valid_data, my_schema)
print(f"Proxy Name: {proxy_data.name}")
print(f"Proxy Age: {proxy_data.age}")
# Trying to set an invalid value (will raise ValidationError)
try:
proxy_data.age = -10
except Exception as e:
print("Attempt to set invalid age via Dataproxy failed as expected:", e)
Errors
Common errors & fixes
jsonschema.exceptions.ValidationError: ... is not valid under any of the given schemas
Data provided for validation does not conform to the defined JSON schema. This can be due to missing required properties, incorrect data types, or values outside specified constraints (e.g., `minimum`, `maxLength`).
fixReview your data against the `Schema` definition. Ensure all `required` fields are present and data types/values match the schema constraints.
ImportError: cannot import name 'Schema' from 'apitools.jsonschema' (or similar for other symbols)
You are trying to import a symbol from an incorrect module path, or the `apitools` library is not correctly installed or accessible in your Python environment.
fixVerify `apitools` is installed (`pip show apitools`). Ensure the import path is exact, e.g., `from apitools.jsonschema import Schema`.
AttributeError: 'Dataproxy' object has no attribute 'some_property'
You are trying to access a property on a `Dataproxy` object that is not defined in the JSON schema it was initialized with, or it's a misspelling.
fixCheck your JSON schema definition to ensure `some_property` is correctly defined under `properties`. `Dataproxy` strictly enforces schema-defined attributes.
TypeError: '<' not supported between instances of 'NoneType' and 'int'
This error often occurs in older validation libraries like `jsonschema` 2.x when a schema expects a specific type (e.g., `integer`) but receives `None`, and a comparison operation (like `minimum` check) is attempted.
fixEnsure all data fields expected to be non-null are indeed populated with appropriate values before validation or `Dataproxy` usage. Add 'null' to the `type` array in your schema if `None` is an allowed value for a property (e.g., `"type": ["string", "null"]`).
Upgrade
Version history
0.1.4latest on PyPI · released Mar 28, 2014
Audit
Dependencies
jsonschemarequiredCore dependency for JSON schema validation.
requestsrequiredUsed for HTTP client functionality in API interactions.
Resources
No resource links recorded.