Apitools
raw JSON → 0.1.4 verified Fri Apr 17 auth: no en abandoned
Apitools (version 0.1.4) is a Python library designed to assist with JSON schema validation and interaction with REST APIs. It provides utilities for defining and validating data against JSON schemas and for creating client proxies for API interactions. The library has not seen updates since 2016, indicating it is no longer actively maintained.
pip install apitools Common errors
error jsonschema.exceptions.ValidationError: ... is not valid under any of the given schemas ↓
cause 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`).
fix
Review your data against the
Schema definition. Ensure all required fields are present and data types/values match the schema constraints. error ImportError: cannot import name 'Schema' from 'apitools.jsonschema' (or similar for other symbols) ↓
cause 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.
fix
Verify
apitools is installed (pip show apitools). Ensure the import path is exact, e.g., from apitools.jsonschema import Schema. error AttributeError: 'Dataproxy' object has no attribute 'some_property' ↓
cause 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.
fix
Check your JSON schema definition to ensure
some_property is correctly defined under properties. Dataproxy strictly enforces schema-defined attributes. error TypeError: '<' not supported between instances of 'NoneType' and 'int' ↓
cause 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.
fix
Ensure 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"]). Warnings
breaking Apitools has a strict dependency on an old version of `jsonschema` (`>=2.5.1`). This is incompatible with modern `jsonschema` versions (4.x+), which have significant API and behavioral changes. Installing `apitools` in an environment with a newer `jsonschema` will likely lead to dependency conflicts or runtime errors. ↓
fix Use a isolated virtual environment with specific `jsonschema<3` or pin `jsonschema==2.5.1` if using `apitools`. Consider migrating to an actively maintained library for JSON schema validation.
gotcha The `apitools` library is abandoned; its last release was in 2016 and there have been no code updates since 2021. It is not maintained, meaning no bug fixes, security patches, or compatibility updates for newer Python versions or libraries will be provided. ↓
fix Be aware that using this library in new projects carries significant risk. Consider modern, actively maintained alternatives for JSON schema validation and API client generation.
gotcha Due to its age and lack of maintenance, `apitools` is unlikely to be fully compatible with recent Python versions (e.g., Python 3.8+). While it targets Python 2 and early Python 3, specific language features or dependency changes in newer Python versions may cause unexpected errors. ↓
fix Test thoroughly in your target Python environment. It is recommended to use `apitools` only in legacy environments (Python 3.6 or older) where it was originally designed to run.
Imports
- Schema
from apitools.jsonschema import Schema - validate
from apitools.jsonschema import validate - Dataproxy
from apitools.dataproxy import Dataproxy - Client
from apitools.client import Client
Quickstart
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)