Convenience wrapper for exonware-xwquery - provides 'import xwquery' alias
Project description
๐ xwquery: Universal Query Language for Python
Company: eXonware.com
Author: eXonware Backend Team
Email: connect@exonware.com
Version: 0.0.1.3
๐ฏ What is xwquery?
xwquery is the universal query language for Python that works across all data structures. Write once, query anywhere - from simple lists to complex graphs, from JSON to XML, from nodes to entities.
Think of it as SQL for everything.
โก Quick Start
Installation
pip install exonware-xwquery
Basic Usage
from exonware.xwquery import XWQuery
# Query any data structure
data = {'users': [
{'name': 'Alice', 'age': 30, 'city': 'NYC'},
{'name': 'Bob', 'age': 25, 'city': 'LA'},
{'name': 'Charlie', 'age': 35, 'city': 'NYC'}
]}
# Use familiar SQL-like syntax
result = XWQuery.execute("""
SELECT name, age
FROM users
WHERE age > 25 AND city = 'NYC'
""", data)
print(result)
# [{'name': 'Alice', 'age': 30}, {'name': 'Charlie', 'age': 35}]
๐ฏ Perfect For:
- ๐ Data Querying - Query any Python data structure with SQL-like syntax
- ๐ Format Conversion - Convert between 35+ query formats (SQL, GraphQL, Cypher, etc.)
- ๐ Data Transformation - Transform and filter data with powerful operations
- ๐ Universal Interface - One query language for nodes, data, schemas, and entities
- ๐ Performance - Optimized execution for different data structure types
๐ Key Features
50 Query Operations
โ
Core CRUD: SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP
โ
Filtering: WHERE, FILTER, BETWEEN, LIKE, IN, HAS, TERM, RANGE
โ
Aggregation: SUM, COUNT, AVG, MIN, MAX, GROUP BY, HAVING
โ
Graph Operations: MATCH, PATH, OUT, IN_TRAVERSE, RETURN
โ
Advanced: JOIN, UNION, WITH, MERGE, WINDOW, PIPE
35+ Format Converters
โ
SQL Dialects: Standard SQL, PostgreSQL, MySQL, SQLite
โ
Graph Queries: Cypher, Gremlin, SPARQL, GraphQL
โ
Document Queries: MongoDB (MQL), CouchDB, Elasticsearch (DSL)
โ
Time Series: PromQL, Flux, LogQL
โ
Data Queries: JQ, JMESPath, JSONiq, XPath, XQuery
โ
And many more...
Type-Aware Execution
# Automatically optimizes based on data structure
linear_data = [1, 2, 3, 4, 5]
tree_data = {'a': 1, 'b': 2, 'c': 3}
graph_data = {'nodes': [...], 'edges': [...]}
# Same query, optimized execution for each type!
XWQuery.execute("SELECT * WHERE value > 2", linear_data) # Sequential scan
XWQuery.execute("SELECT * WHERE key BETWEEN 'a' AND 'c'", tree_data) # Tree traversal
XWQuery.execute("MATCH (n)-[r]->(m)", graph_data) # Graph algorithm
๐ XWQuery Script Language
Comprehensive Syntax
-- Data retrieval
SELECT name, email, age FROM users WHERE age >= 18;
-- Aggregation
SELECT
department,
COUNT(*) as employee_count,
AVG(salary) as avg_salary
FROM employees
GROUP BY department
HAVING avg_salary > 50000;
-- Graph pattern matching
MATCH (u:User)-[:FRIENDS_WITH]->(f:User)
WHERE u.age > 25
RETURN u.name, f.name;
-- Data transformation
PIPE users
|> FILTER age > 18
|> EXTEND full_name = CONCAT(first_name, ' ', last_name)
|> PROJECT user_id, full_name, email
|> ORDER BY full_name;
-- Complex joins
SELECT u.name, o.total_amount
FROM users u
INNER JOIN orders o ON u.id = o.user_id
WHERE o.order_date >= '2024-01-01';
-- Window functions
SELECT
product_id,
price,
AVG(price) OVER (PARTITION BY category) as avg_category_price
FROM products;
Format Conversion
# Parse SQL, convert to GraphQL
sql_query = "SELECT id, name FROM users WHERE age > 25"
graphql = XWQuery.convert(sql_query, from_format='sql', to_format='graphql')
# Result: "query { users(filter: {age: {gt: 25}}) { id name } }"
# Parse Cypher, convert to SQL
cypher_query = "MATCH (u:User)-[:WORKS_AT]->(c:Company) RETURN u.name, c.name"
sql = XWQuery.convert(cypher_query, from_format='cypher', to_format='sql')
# Result: "SELECT u.name, c.name FROM users u JOIN companies c ON ..."
# Universal intermediate representation
any_query = XWQuery.parse(query_string) # Parses to actions tree
target_format = any_query.to_format('mongodb') # Convert to any format
๐ Integration with exonware Stack
Query Nodes (xwnode)
from exonware.xwnode import XWNode
from exonware.xwquery import XWQuery
node = XWNode.from_native({'users': [...]})
result = XWQuery.execute("SELECT * FROM users WHERE active = true", node)
Query Data (xwdata)
from exonware.xwdata import XWData
from exonware.xwquery import XWQuery
# Load, query, convert format
data = XWData.load('users.json')
filtered = XWQuery.execute("SELECT * WHERE age > 18", data)
filtered.save('adults.xml') # Save in different format!
Query Entities (xwentity)
from exonware.xwentity import XWEntity
from exonware.xwquery import XWQuery
class User(XWEntity):
name: str
age: int
email: str
# Schema-validated queries
users = XWQuery.execute("SELECT * FROM User WHERE age > 18")
# โ
Validates 'age' exists in schema
# โ
Ensures age is int type
# โ
Returns typed User entities
๐ Examples
Example 1: Simple Filtering
products = [
{'id': 1, 'name': 'Laptop', 'price': 999, 'category': 'Electronics'},
{'id': 2, 'name': 'Mouse', 'price': 29, 'category': 'Electronics'},
{'id': 3, 'name': 'Desk', 'price': 299, 'category': 'Furniture'},
]
result = XWQuery.execute("""
SELECT name, price
FROM products
WHERE category = 'Electronics' AND price < 500
""", products)
# [{'name': 'Mouse', 'price': 29}]
Example 2: Aggregation
orders = [
{'user_id': 1, 'amount': 100},
{'user_id': 1, 'amount': 200},
{'user_id': 2, 'amount': 150},
{'user_id': 2, 'amount': 300},
]
result = XWQuery.execute("""
SELECT
user_id,
COUNT(*) as order_count,
SUM(amount) as total_spent,
AVG(amount) as avg_order
FROM orders
GROUP BY user_id
HAVING total_spent > 200
""", orders)
# [
# {'user_id': 1, 'order_count': 2, 'total_spent': 300, 'avg_order': 150},
# {'user_id': 2, 'order_count': 2, 'total_spent': 450, 'avg_order': 225}
# ]
Example 3: Graph Traversal
graph = {
'nodes': [
{'id': 1, 'type': 'User', 'name': 'Alice'},
{'id': 2, 'type': 'User', 'name': 'Bob'},
{'id': 3, 'type': 'Post', 'title': 'Hello World'}
],
'edges': [
{'from': 1, 'to': 2, 'type': 'FRIENDS_WITH'},
{'from': 1, 'to': 3, 'type': 'AUTHORED'}
]
}
result = XWQuery.execute("""
MATCH (u:User)-[:FRIENDS_WITH]->(friend:User)
WHERE u.name = 'Alice'
RETURN u.name, friend.name
""", graph)
# [{'u.name': 'Alice', 'friend.name': 'Bob'}]
Example 4: Format Conversion
# SQL to MongoDB
sql = "SELECT name, email FROM users WHERE age > 25"
mongo = XWQuery.convert(sql, to_format='mongodb')
# db.users.find({age: {$gt: 25}}, {name: 1, email: 1})
# GraphQL to SQL
graphql = "query { users(filter: {active: true}) { id name email } }"
sql = XWQuery.convert(graphql, to_format='sql')
# SELECT id, name, email FROM users WHERE active = true
# Cypher to SPARQL
cypher = "MATCH (a:Person)-[:KNOWS]->(b:Person) RETURN a.name, b.name"
sparql = XWQuery.convert(cypher, to_format='sparql')
# SELECT ?aName ?bName WHERE { ?a rdf:type :Person . ?a :KNOWS ?b . ... }
๐๏ธ Architecture
Query Execution Flow
User Query String
โ
[Parser] - Parse to Actions Tree
โ
[Capability Checker] - Validate operation compatibility
โ
[Executor Registry] - Get appropriate executor
โ
[Type-Aware Execution] - Optimized for data structure type
โ
Result
Supported Node Types
- LINEAR: Arrays, lists, queues, stacks
- TREE: Hash maps, B-trees, AVL trees, tries
- GRAPH: Adjacency lists, graph structures
- MATRIX: Bitmaps, sparse matrices
- HYBRID: Combined structures
Each query operation automatically adapts to the node type for optimal performance.
๐ Documentation
- Complete Query Syntax - All 50 operations detailed
- Format Converters - 35+ format conversion guide
- API Reference - Complete API documentation
- Examples - Practical usage examples
- Integration Guide - Using with xwnode, xwdata, xwentity
๐ Project Phases
xwquery follows a structured 5-phase development approach designed to deliver enterprise-grade functionality.
Current Phase: ๐งช Version 0 - Experimental Stage
- Focus: Core query engine, format converters, execution optimization
- Status: ๐ข ACTIVE - Foundation complete with 50 operations
Development Roadmap:
- Version 1 (Q1 2026): Production Ready - Performance optimization
- Version 2 (Q2 2026): Query Optimization - Smart query planning
- Version 3 (Q3 2026): Distributed Queries - Parallel execution
- Version 4 (Q4 2026): Mars Standard Implementation - Universal interoperability
๐ง Development
# Install in development mode
pip install -e .
# Run tests
python tests/runner.py
# Run specific test types
python tests/runner.py --core
python tests/runner.py --unit
python tests/runner.py --integration
๐ Why xwquery?
Before xwquery:
# Different syntax for different data structures
list_result = [x for x in data if x['age'] > 25] # List comprehension
dict_result = {k: v for k, v in data.items() if v > 25} # Dict comprehension
df_result = df[df['age'] > 25] # Pandas
collection.find({'age': {'$gt': 25}}) # MongoDB
# ... and so on
With xwquery:
# One syntax for everything
result = XWQuery.execute("SELECT * WHERE age > 25", data)
# Works with: lists, dicts, nodes, dataframes, graphs, entities, etc.
Key Benefits:
- Universal Interface - One query language for all data structures
- Format Agnostic - Query JSON, save as XML, load CSV, export as YAML
- Type-Aware - Automatically optimizes for data structure type
- Production-Grade - Built on proven patterns and best practices
- Extensible - Easy to add custom operations and formats
- Performance - Optimized execution for each node type
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run the test suite
- Submit a pull request
๐ License
MIT License - see LICENSE file for details.
Built with โค๏ธ by eXonware.com - Making universal data querying effortless
๐ Part of the exonware Ecosystem
- xwsystem - Core system utilities
- xwnode - Node-based data structures
- xwquery - Universal query language โญ You are here
- xwdata - Format-agnostic data manipulation
- xwschema - Schema validation
- xwaction - Action definitions
- xwentity - Entity management
- xwstorage - Storage abstraction
- xwbase - Firebase-like backend
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 xwquery-0.0.1.9.tar.gz.
File metadata
- Download URL: xwquery-0.0.1.9.tar.gz
- Upload date:
- Size: 496.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d570aeb88faa61b3319b27263d28be87178b9dc1ad024e8c50197a6888b25244
|
|
| MD5 |
593ac8f18a3a2697ae419f9a611fe761
|
|
| BLAKE2b-256 |
03557512c5215836dc6f9f865f9505df2fc0f1222417ad6fd381b1dc4c300315
|
File details
Details for the file xwquery-0.0.1.9-py3-none-any.whl.
File metadata
- Download URL: xwquery-0.0.1.9-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b10836d2ea55aa342cc8bac38b311919fe288e419ffd36174a021b321becb023
|
|
| MD5 |
6dc3dfcd34f63abc6bfd18f14babb3d8
|
|
| BLAKE2b-256 |
bddcd1005e0a01f60cd5f0b3a37979a556a7e3474fd76a34cc4cc547d3c1469d
|