An embedded domain-specific language for spatial sensor fusion and AI
Project description
███████╗██████╗ █████╗ ██╗ ██╗██╗ ██████╗ ███╗ ███╗
██╔════╝██╔══██╗██╔══██╗╚██╗██╔╝██║██╔═══██╗████╗ ████║
███████╗██████╔╝███████║ ╚███╔╝ ██║██║ ██║██╔████╔██║
╚════██║██╔═══╝ ██╔══██║ ██╔██╗ ██║██║ ██║██║╚██╔╝██║
███████║██║ ██║ ██║██╔╝ ██╗██║╚██████╔╝██║ ╚═╝ ██║
╚══════╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═╝
# Spaxiom-DSL
[](https://pypi.org/project/spaxiom/)
[](https://github.com/joescanlin/spaxiom-dsl/actions/workflows/ci.yml)
[](https://github.com/joescanlin/spaxiom-dsl)
An embedded domain-specific language for spatial sensor fusion, temporal reasoning, and real-time event detection.
╔═══════════╗ ╔═══════════╗
║ SENSORS ║ ║ DETECTION ║
║ ●━━━━━━━━━║═══════════════════║━━━━━━━━━● ║
║ ●━━━━━━━━━║═══════════════════║━━━━━━━━━● ║
╚═══════════╝ ╚═══════════╝
│ ▲
▼ │
╔═══════════╗ ╔═══════════╗ ╔═══════════╗
║ ║ ║ ║ ║ ║
║ SPATIAL ║════>║ TEMPORAL ║════>║ EVENTS ║
║ ║ ║ ║ ║ ║
╚═══════════╝ ╚═══════════╝ ╚═══════════╝
## What is Spaxiom?
Spaxiom is a powerful Domain-Specific Language (DSL) designed for building intelligent systems that work with:
- **Spatial Data**: Zones, sensors, and physical spaces
- **Temporal Logic**: Time-based conditions and historical analysis
- **Event Processing**: Triggering actions based on complex conditions
- **Entity Management**: Tracking and querying objects in your system
- **Physical Units**: Working with measurements in a type-safe manner
With Spaxiom, you can easily define complex conditions that span across space and time, and connect them to real-world events.
## Key Features
- 🏠 **Spatial Zones**: Define and work with 2D spatial regions
- ⚡ **Sensors**: Interface with various sensor types and data streams
- ⏱️ **Temporal Logic**: Create conditions that must be true for specific durations
- 🔄 **Event Callbacks**: Register event handlers triggered by complex conditions
- 👥 **Entity Tracking**: Maintain collections of entities with flexible attributes
- 📏 **Physical Units**: Work with measurements and conversions seamlessly
- 🧩 **Logical Operators**: Combine conditions using intuitive &, |, and ~ operators
- 📄 **YAML Configuration**: Define sensors and system setup through YAML files
## Installation
```bash
pip install -e .
Quick Examples
Spatial & Temporal Logic
from spaxiom import Sensor, Zone, Condition, on, within
# Define a zone and sensor
office_zone = Zone(0, 0, 10, 10)
motion_sensor = Sensor("motion1", "motion", (5, 5, 0))
# Create condition based on sensor data
motion_detected = Condition(lambda: motion_sensor.read() > 0.5)
# Make it temporal - must be true for 5 seconds
sustained_motion = within(5.0, motion_detected)
# Register an event handler
@on(sustained_motion)
def alert_sustained_motion():
print("Motion has been detected for 5 seconds!")
Entity Management
from spaxiom import EntitySet, Entity, exists, on, Condition
# Create a collection of entities
persons = EntitySet("Persons")
# Add entities with attributes
persons.add(Entity(attrs={"type": "person", "confidence": 0.9}))
# Create condition based on entity existence
person_detected = exists(persons, lambda p: p.attrs.get("confidence", 0) > 0.8)
# Register an event handler
@on(person_detected)
def alert_person():
print("Person detected with high confidence!")
Physical Units
from spaxiom import Quantity
# Create measurements with units
distance = Quantity(10, "m")
time = Quantity(2, "s")
# Automatic unit conversion
speed = distance / time # 5 m/s
# Convert to different units
speed_kph = speed.to("km/hour") # 18 km/h
YAML Configuration
from spaxiom import load_sensors_from_yaml, on, Condition, within
# Load sensors from YAML configuration file
sensors = load_sensors_from_yaml("sensors_config.yaml")
# Access sensors by name from the registry
from spaxiom import SensorRegistry
registry = SensorRegistry()
motion_sensor = registry.get("motion_sensor1")
# Create condition based on sensor from config
motion_detected = Condition(lambda: motion_sensor.read() > 0.5)
# Register event handler
@on(motion_detected)
def alert_motion():
print("Motion detected!")
Example YAML configuration:
sensors:
- name: motion_sensor1
type: gpio_digital
pin: 17
location: [0, 0, 0]
pull_up: true
- name: temperature_sensor1
type: random
location: [1, 2, 0]
hz: 5.0
Documentation
Online Documentation
The full documentation is available online at: https://joescanlin.github.io/spaxiom-dsl/
Local Documentation
For local development, you can build and view the documentation using MkDocs:
# Install MkDocs and required extensions
pip install mkdocs-material pymdown-extensions
# Serve the documentation locally
mkdocs serve
# Build the documentation
mkdocs build
The documentation source files are located in the docs/ directory. Some key sections:
Documentation Updates
The documentation is automatically deployed to GitHub Pages when changes are pushed to the main branch.
Changes to files in the docs/ directory or to mkdocs.yml will trigger a new build and deployment.
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spaxiom-0.1.0rc1.tar.gz.
File metadata
- Download URL: spaxiom-0.1.0rc1.tar.gz
- Upload date:
- Size: 37.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b03fa2ec8b45ee43afeeb4092b62aff029c578203bdea9c7dc9be61cd4bcc10
|
|
| MD5 |
ee9db5f16f8c4770ec897d491bb376a5
|
|
| BLAKE2b-256 |
bfbb0c33be1595b14f0b367891d4e8cf44df9b07cbd8dde94ca0b786f98fed5c
|
File details
Details for the file spaxiom-0.1.0rc1-py3-none-any.whl.
File metadata
- Download URL: spaxiom-0.1.0rc1-py3-none-any.whl
- Upload date:
- Size: 48.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5937112b1d5eabc207d3992e5a9de1d82e765a7b092a7def6892697a5264406a
|
|
| MD5 |
ca6583133da093ac2ca33554f599a3ba
|
|
| BLAKE2b-256 |
d6bc2b0d4b6a8c98b409c1ef374d18f0e59dfefef893db2a56716f4dae95b236
|