mgraph-ai


Namemgraph-ai JSON
Version 0.11.0 PyPI version JSON
download
home_pageNone
SummaryMGraph-AI
upload_time2025-01-29 02:09:34
maintainerNone
docs_urlNone
authorDinis Cruz
requires_python<4.0,>=3.11
licenseApache 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MGraph-AI - A Memory-based GraphDB for GenAI, Semantic Web and Serverless

![Current Release](https://img.shields.io/badge/release-v0.11.0-blue)

MGraph-AI is a lightweight, memory-first graph database implementation in Python, designed specifically for AI, semantic web, 
and serverless applications. What sets it apart is its focus on in-memory performance while maintaining persistence through 
serialized JSON data structures. This makes it particularly well-suited for:

- AI/ML applications requiring fast graph traversals
- Serverless environments where quick startup and low memory overhead are crucial
- Semantic web applications needing flexible graph structures
- Applications requiring both graph capabilities and JSON compatibility

The library provides a robust, type-safe implementation with a clean, layered architecture that prioritizes maintainability 
and scalability. By keeping the graph in memory and serializing to JSON, MGraph-AI achieves excellent performance from small to read-heavy 
workloads while maintaining data persistence.

## Features

- Memory-first architecture with JSON serialization for persistence
- High-performance graph operations optimized for in-memory access
- Type-safe implementation with comprehensive validation
- Clean, layered architecture with focused action interfaces
- Rich attribute support for nodes and edges
- Extensible storage backends with JSON as the primary format
- Minimal dependencies making it ideal for serverless deployments
- Built-in support for semantic web concepts
- Optimized for AI/ML workloads
- Small memory footprint with efficient serialization

## Installation

```bash
pip install mgraph-ai
```

## Quick Start

```python
from mgraph_ai.mgraph import MGraph
from osbot_utils.helpers.Safe_Id import Safe_Id

# Create a new graph
mgraph = MGraph()

# Add nodes and edges
with mgraph.edit() as edit:
    # Create nodes
    node1 = edit.new_node(value="Node 1")
    node2 = edit.new_node(value="Node 2")
    
    # Add attributes to nodes
    node1.add_attribute(name=Safe_Id("color"), value="blue")
    node2.add_attribute(name=Safe_Id("size"), value=5)
    
    # Create an edge between nodes
    edge = edit.new_edge(from_node_id=node1.node_id(), 
                        to_node_id=node2.node_id())
    
    # Add attribute to edge
    edge.add_attribute(name=Safe_Id("weight"), value=1.5)

# Query the graph
with mgraph.data() as data:
    # Get all nodes
    nodes = data.nodes()
    
    # Get all edges
    edges = data.edges()
    
    # Get specific node
    node = data.node(node1.node_id())
```

## Architecture

MGraph-AI implements a layered architecture:

```
Actions Layer (Data, Edit, Filter, Storage)
    ↓
Model Layer (Business Logic)
    ↓
Schema Layer (Type Definitions)
```

### Action Classes

Operations are organized into focused interfaces:

- `MGraph__Data`: Read operations and queries
- `MGraph__Edit`: Modification operations
- `MGraph__Filter`: Search and filtering capabilities
- `MGraph__Storage`: Persistence operations

### Type Safety

MGraph-AI enforces type safety at all layers:

```python
# Type-safe node creation
node = edit.new_node(value="test", value_type=str)  # OK
node = edit.new_node(value=123, value_type=str)     # Raises TypeError

# Type-safe attribute addition
node.add_attribute(name=Safe_Id("count"), 
                  value=42, 
                  attr_type=int)  # OK
```

## Advanced Usage

### Custom Node Types

```python
from mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node

class Custom_Node(Schema__MGraph__Node):
    def custom_method(self):
        return f"Node value: {self.value}"

# Use custom node type
mgraph = MGraph(node_type=Custom_Node)
```

### Graph Persistence

```python
# Save graph state
with mgraph.storage() as storage:
    storage.save()

# Create new graph
with mgraph.storage() as storage:
    storage.create()

# Delete graph
with mgraph.storage() as storage:
    storage.delete()
```

### Attribute Operations

```python
# Add typed attributes
node.add_attribute(name=Safe_Id("count"), value=42, attr_type=int)
node.add_attribute(name=Safe_Id("name"), value="test", attr_type=str)

# Get attribute value
attr = node.attribute(attribute_id)
value = attr.value()

# Get all attributes
attributes = node.attributes()
```

## Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## Development Setup

```bash
# Clone the repository
git clone https://github.com/owasp-sbot/MGraph-AI.git
cd MGraph-AI

# Install dependencies with Poetry
poetry install

# Enter the poetry shell
poetry shell

# Run tests
poetry run pytest tests/
```

## License

This project is licensed under the Apache 2.0 License 2.0 - see the [LICENSE](LICENSE) file for details.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "mgraph-ai",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": null,
    "author": "Dinis Cruz",
    "author_email": "dinis.cruz@owasp.org",
    "download_url": "https://files.pythonhosted.org/packages/6b/86/0d6d99fff245e1b62ac8bc8f447c635b040cd2bc7db7dfef1c75167eae5e/mgraph_ai-0.11.0.tar.gz",
    "platform": null,
    "description": "# MGraph-AI - A Memory-based GraphDB for GenAI, Semantic Web and Serverless\n\n![Current Release](https://img.shields.io/badge/release-v0.11.0-blue)\n\nMGraph-AI is a lightweight, memory-first graph database implementation in Python, designed specifically for AI, semantic web, \nand serverless applications. What sets it apart is its focus on in-memory performance while maintaining persistence through \nserialized JSON data structures. This makes it particularly well-suited for:\n\n- AI/ML applications requiring fast graph traversals\n- Serverless environments where quick startup and low memory overhead are crucial\n- Semantic web applications needing flexible graph structures\n- Applications requiring both graph capabilities and JSON compatibility\n\nThe library provides a robust, type-safe implementation with a clean, layered architecture that prioritizes maintainability \nand scalability. By keeping the graph in memory and serializing to JSON, MGraph-AI achieves excellent performance from small to read-heavy \nworkloads while maintaining data persistence.\n\n## Features\n\n- Memory-first architecture with JSON serialization for persistence\n- High-performance graph operations optimized for in-memory access\n- Type-safe implementation with comprehensive validation\n- Clean, layered architecture with focused action interfaces\n- Rich attribute support for nodes and edges\n- Extensible storage backends with JSON as the primary format\n- Minimal dependencies making it ideal for serverless deployments\n- Built-in support for semantic web concepts\n- Optimized for AI/ML workloads\n- Small memory footprint with efficient serialization\n\n## Installation\n\n```bash\npip install mgraph-ai\n```\n\n## Quick Start\n\n```python\nfrom mgraph_ai.mgraph import MGraph\nfrom osbot_utils.helpers.Safe_Id import Safe_Id\n\n# Create a new graph\nmgraph = MGraph()\n\n# Add nodes and edges\nwith mgraph.edit() as edit:\n    # Create nodes\n    node1 = edit.new_node(value=\"Node 1\")\n    node2 = edit.new_node(value=\"Node 2\")\n    \n    # Add attributes to nodes\n    node1.add_attribute(name=Safe_Id(\"color\"), value=\"blue\")\n    node2.add_attribute(name=Safe_Id(\"size\"), value=5)\n    \n    # Create an edge between nodes\n    edge = edit.new_edge(from_node_id=node1.node_id(), \n                        to_node_id=node2.node_id())\n    \n    # Add attribute to edge\n    edge.add_attribute(name=Safe_Id(\"weight\"), value=1.5)\n\n# Query the graph\nwith mgraph.data() as data:\n    # Get all nodes\n    nodes = data.nodes()\n    \n    # Get all edges\n    edges = data.edges()\n    \n    # Get specific node\n    node = data.node(node1.node_id())\n```\n\n## Architecture\n\nMGraph-AI implements a layered architecture:\n\n```\nActions Layer (Data, Edit, Filter, Storage)\n    \u2193\nModel Layer (Business Logic)\n    \u2193\nSchema Layer (Type Definitions)\n```\n\n### Action Classes\n\nOperations are organized into focused interfaces:\n\n- `MGraph__Data`: Read operations and queries\n- `MGraph__Edit`: Modification operations\n- `MGraph__Filter`: Search and filtering capabilities\n- `MGraph__Storage`: Persistence operations\n\n### Type Safety\n\nMGraph-AI enforces type safety at all layers:\n\n```python\n# Type-safe node creation\nnode = edit.new_node(value=\"test\", value_type=str)  # OK\nnode = edit.new_node(value=123, value_type=str)     # Raises TypeError\n\n# Type-safe attribute addition\nnode.add_attribute(name=Safe_Id(\"count\"), \n                  value=42, \n                  attr_type=int)  # OK\n```\n\n## Advanced Usage\n\n### Custom Node Types\n\n```python\nfrom mgraph_ai.mgraph.schemas.Schema__MGraph__Node import Schema__MGraph__Node\n\nclass Custom_Node(Schema__MGraph__Node):\n    def custom_method(self):\n        return f\"Node value: {self.value}\"\n\n# Use custom node type\nmgraph = MGraph(node_type=Custom_Node)\n```\n\n### Graph Persistence\n\n```python\n# Save graph state\nwith mgraph.storage() as storage:\n    storage.save()\n\n# Create new graph\nwith mgraph.storage() as storage:\n    storage.create()\n\n# Delete graph\nwith mgraph.storage() as storage:\n    storage.delete()\n```\n\n### Attribute Operations\n\n```python\n# Add typed attributes\nnode.add_attribute(name=Safe_Id(\"count\"), value=42, attr_type=int)\nnode.add_attribute(name=Safe_Id(\"name\"), value=\"test\", attr_type=str)\n\n# Get attribute value\nattr = node.attribute(attribute_id)\nvalue = attr.value()\n\n# Get all attributes\nattributes = node.attributes()\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## Development Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/owasp-sbot/MGraph-AI.git\ncd MGraph-AI\n\n# Install dependencies with Poetry\npoetry install\n\n# Enter the poetry shell\npoetry shell\n\n# Run tests\npoetry run pytest tests/\n```\n\n## License\n\nThis project is licensed under the Apache 2.0 License 2.0 - see the [LICENSE](LICENSE) file for details.\n\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "MGraph-AI",
    "version": "0.11.0",
    "project_urls": {
        "Homepage": "https://github.com/owasp-sbot/MGraph-AI",
        "Repository": "https://github.com/owasp-sbot/MGraph-AI"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7837ac539b24d81378e86c19304e9a5662141a16570e4362da906a3507358772",
                "md5": "210c7175c05ce20927972a7bf1ce1c2b",
                "sha256": "30847df9e6860c472305117cda1233e4f248f3666b9a9ba03a01e96a40abe545"
            },
            "downloads": -1,
            "filename": "mgraph_ai-0.11.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "210c7175c05ce20927972a7bf1ce1c2b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 114878,
            "upload_time": "2025-01-29T02:09:31",
            "upload_time_iso_8601": "2025-01-29T02:09:31.749253Z",
            "url": "https://files.pythonhosted.org/packages/78/37/ac539b24d81378e86c19304e9a5662141a16570e4362da906a3507358772/mgraph_ai-0.11.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b860d6d99fff245e1b62ac8bc8f447c635b040cd2bc7db7dfef1c75167eae5e",
                "md5": "ffefbcf17a91aef863ce3d26570e5863",
                "sha256": "82a39469f224d90cad0f5f5ba635748498733d0cc72bf6550c52f022736d58a0"
            },
            "downloads": -1,
            "filename": "mgraph_ai-0.11.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ffefbcf17a91aef863ce3d26570e5863",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 57680,
            "upload_time": "2025-01-29T02:09:34",
            "upload_time_iso_8601": "2025-01-29T02:09:34.163161Z",
            "url": "https://files.pythonhosted.org/packages/6b/86/0d6d99fff245e1b62ac8bc8f447c635b040cd2bc7db7dfef1c75167eae5e/mgraph_ai-0.11.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-29 02:09:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "owasp-sbot",
    "github_project": "MGraph-AI",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mgraph-ai"
}
        
Elapsed time: 1.00656s