In the data-models repository you can access to the first version to use smart data models as a service. Thanks to the works for the Cyclops project.
The files available create a wrap up around pysmartdatamodels package and also add one service for the online validation of NGSI-LD payloads.
Here is the readme contents to have an explanation of this first version
Smart Data Models API and Demo
This project consists of two main components:
- A FastAPI-based web service (
pysdm_api3.py
) that provides access to Smart Data Models functionality - A demo script (
demo_script2.py
) that demonstrates the API endpoints - A requirements file for the components use
- A bash script to run it
API Service (pysdm_api3.py
)
A RESTful API that interfaces with the pysmartdatamodels
library to provide access to Smart Data Models functionality.
Key Features
- Payload Validation: Validate JSON payloads against Smart Data Models schemas
- Data Model Exploration: Browse subjects, data models, and their attributes
- Search Functionality: Find data models by exact or approximate name matching
- Context Retrieval: Get @context information for data models
- if you need other please email us to info @ smartdatamodels. org
Endpoints
Endpoint | Method | Description |
---|---|---|
/validate-url |
GET | Validate a JSON payload from a URL against Smart Data Models |
/subjects |
GET | List all available subjects |
/datamodels/{subject_name} |
GET | List data models for a subject |
/datamodels/{subject_name}/{datamodel_name}/attributes |
GET | Get attributes of a data model |
/datamodels/{subject_name}/{datamodel_name}/example |
GET | Get an example payload of a data model |
/search/datamodels/{name_pattern}/{likelihood} |
GET | Search for data models by approximate name |
/datamodels/exact-match/{datamodel_name} |
GET | Find a data model by exact name |
/subjects/exact-match/{subject_name} |
GET | Check if a subject exists by exact name |
/datamodels/{datamodel_name}/contexts |
GET | Get @context(s) for a data model name |
Validation Process
The /validate-url
endpoint performs comprehensive validation:
- Fetches JSON from the provided URL
- Normalizes NGSI-LD payloads to key-values format
- Extracts the payload type
- Finds all subjects containing this type
- Retrieves schemas for each subject
- Validates against all schemas
- Returns consolidated results
Demo Script (demo_script2.py
)
A simple interactive script that demonstrates the API endpoints by opening a series of pre-configured URLs in your default web browser.
Features
- Opens each URL in a new browser tab
- Pauses between URLs for user input
- Allows early termination with ‘exit’ command
- Provides clear progress indicators
Usage
- Configure the URLs in the
my_web_urls
list - Run the script:
python demo_script2.py
- Follow the on-screen instructions
The demo includes examples of:
- Payload validation
- Subject listing
- Data model exploration
- Attribute retrieval
- Example payloads
- Search functionality
- Exact matching
- Context retrieval
Requirements
- Python 3.7+
- FastAPI
- Uvicorn
- httpx
- pydantic
- jsonschema
- webbrowser (standard library)
Installation
pip install fastapi uvicorn httpx pydantic jsonschema
Running the API
python pysdm_api3.py
Running the demo
python demo_script2.py
Configuration
Edit the my_web_urls list in demo_script2.py to change which endpoints are demonstrated.
License
Apache 2.0