## Purpose of the Package
+ To translate from Pydantic models to Neo4j Graphs
## Getting Started
+ Install the package
```bash
pip install pydantic-neo4j
```
## Usage
+ Import the package and models
```python
from pydantic_neo4j import (PydanticNeo4j,
RelationshipQueryModel,
NodeModel,
SequenceCriteriaNodeModel,
SequenceCriteriaRelationshipModel,
SequenceQueryModel,
SequenceNodeModel)
```
___
+ Initialize the class and get the utilities
```python
pydantic_neo4j = PydanticNeo4j(username='neo4j', password='neo4j', uri='neo4j://localhost:7687)
match_util = pydantic_neo4j.match_utilities
create_util = pydantic_neo4j.create_utilities
database_operations = pydantic_neo4j.database_operations
```
___
+ Create some Pydantic models
```python
class Manufacturer(NodeModel):
name: str
class Design(NodeModel):
color: str
class Component(NodeModel):
name: str
class IsOrderable(RelationshipModel):
pass
class Produces(RelationshipModel):
design_revision: int
```
___
+ Create the nodes and relationships. All relationships must have a start_node and end_node
```python
relationships = []
manufacturer = Manufacturer(name="Acme")
design = Design(color="red")
produces = Produces(design_revision=3, start_node=manufacturer, end_node=design)
```
+ Add to list
```python
relationships.append(produces)
```
+ Create another relationship and add it to the list
```python
component = Component(component_type="widget")
is_orderable = IsOrderable(start_node=design, end_node=component)
relationships.append(is_orderable)
```
+ Add the nodes and relationships to the graph
```python
await create_util.create_relationships(relationships=relationships)
````
___
+ Query the graph for a single node. Lets find a manufacturer
```python
nodes = await match_util.node_query(node_name='Manufacturer')
___
```
+ Query the graph for multiple nodes. Lets find all nodes that are active
```python
nodes = await match_util.node_query(criteria={'active': True})
```
___
+ Query the graph for a single relationship. Lets find a manufacturer that produces a red design
+ This will be depreciated soon, use sequence query instead
```python
query = RelationshipQueryModel(
start_node_name="Manufacturer",
start_criteria={},
end_node_name="Design",
end_criteria={"color": "red"},
relationship_name="Produces",
relationship_criteria={})
result = await match_util.match_relationship(query=query)
```
___
+ Query the graph for multiple relationships. Lets find all manufacturers that make a widget component
+ This uses a sequence, which is a series of relationships. Similar to Neo4j Path
```python
sequence_query = SequenceQueryModel()
sequence_query.node_sequence.append(SequenceCriteriaNodeModel(name='Manufacturer'))
sequence_query.relationship_sequence.append(SequenceCriteriaRelationshipModel()) # a relationship with no criteria
sequence_query.node_sequence.append(SequenceCriteriaNodeModel() # a node with no criteria specified
sequence_query.relationship_sequence.append(SequenceCriteriaRelationshipModel()) #a realtoinship with no criteria
sequence_query.node_sequence.append(SequenceCriteriaNodeModel(component_type="widget",
include_with_return=True))
```
+ The sequence query must always have 1 more node than relationship.
+ The order is important, and is a sequence. node - relationship - node - relationship - node
```python
result = await match_util.sequence_query(sequence_query=sequence_query)
```
___
+ Run a specific query, lets delete everything
```python
await database_operations.run_query(query=f"match (n) detach delete n")
```
### Not Implemented
+ Update a node
___
+ Update a sequence
___
+ Delete a node
___
Raw data
{
"_id": null,
"home_page": "https://github.com/Michaelzag/PydanticNeo4j",
"name": "pydantic-neo4j",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.11,<4.0",
"maintainer_email": "",
"keywords": "neo4j-pydantic,Pydantic,Neo4j,OGM,Neo4j-OG,MichaelZag",
"author": "MichaelZag",
"author_email": "Michael@MichaelZag.com",
"download_url": "https://files.pythonhosted.org/packages/72/55/e3e87beecc6c61545fb7972f3b0665239bd4e1c86c443354981cbfd46a8d/pydantic_neo4j-0.3.7.tar.gz",
"platform": null,
"description": "\n\n## Purpose of the Package\n+ To translate from Pydantic models to Neo4j Graphs\n\n## Getting Started\n+ Install the package\n```bash\npip install pydantic-neo4j\n```\n\n## Usage\n+ Import the package and models\n```python\nfrom pydantic_neo4j import (PydanticNeo4j, \n RelationshipQueryModel,\n NodeModel,\n SequenceCriteriaNodeModel,\n SequenceCriteriaRelationshipModel, \n SequenceQueryModel, \n SequenceNodeModel)\n```\n___\n+ Initialize the class and get the utilities\n```python\n\npydantic_neo4j = PydanticNeo4j(username='neo4j', password='neo4j', uri='neo4j://localhost:7687)\nmatch_util = pydantic_neo4j.match_utilities\ncreate_util = pydantic_neo4j.create_utilities\ndatabase_operations = pydantic_neo4j.database_operations\n```\n___\n+ Create some Pydantic models\n```python\nclass Manufacturer(NodeModel):\n name: str\n\nclass Design(NodeModel):\n color: str\n \nclass Component(NodeModel):\n name: str\n \nclass IsOrderable(RelationshipModel):\n pass\n\nclass Produces(RelationshipModel):\n design_revision: int\n```\n___\n+ Create the nodes and relationships. All relationships must have a start_node and end_node\n```python\nrelationships = []\n\nmanufacturer = Manufacturer(name=\"Acme\")\ndesign = Design(color=\"red\")\nproduces = Produces(design_revision=3, start_node=manufacturer, end_node=design)\n```\n+ Add to list\n```python\nrelationships.append(produces)\n```\n+ Create another relationship and add it to the list\n```python\ncomponent = Component(component_type=\"widget\")\nis_orderable = IsOrderable(start_node=design, end_node=component)\n\nrelationships.append(is_orderable)\n```\n\n+ Add the nodes and relationships to the graph\n```python\nawait create_util.create_relationships(relationships=relationships)\n````\n___\n+ Query the graph for a single node. Lets find a manufacturer\n```python\nnodes = await match_util.node_query(node_name='Manufacturer')\n___\n```\n+ Query the graph for multiple nodes. Lets find all nodes that are active\n```python\nnodes = await match_util.node_query(criteria={'active': True})\n```\n___\n+ Query the graph for a single relationship. Lets find a manufacturer that produces a red design\n+ This will be depreciated soon, use sequence query instead\n```python\nquery = RelationshipQueryModel(\n start_node_name=\"Manufacturer\",\n start_criteria={},\n end_node_name=\"Design\",\n end_criteria={\"color\": \"red\"},\n relationship_name=\"Produces\",\n relationship_criteria={})\nresult = await match_util.match_relationship(query=query)\n```\n___\n+ Query the graph for multiple relationships. Lets find all manufacturers that make a widget component\n+ This uses a sequence, which is a series of relationships. Similar to Neo4j Path\n```python\nsequence_query = SequenceQueryModel()\n\nsequence_query.node_sequence.append(SequenceCriteriaNodeModel(name='Manufacturer'))\nsequence_query.relationship_sequence.append(SequenceCriteriaRelationshipModel()) # a relationship with no criteria\nsequence_query.node_sequence.append(SequenceCriteriaNodeModel() # a node with no criteria specified\nsequence_query.relationship_sequence.append(SequenceCriteriaRelationshipModel()) #a realtoinship with no criteria\nsequence_query.node_sequence.append(SequenceCriteriaNodeModel(component_type=\"widget\", \n include_with_return=True))\n```\n+ The sequence query must always have 1 more node than relationship.\n+ The order is important, and is a sequence. node - relationship - node - relationship - node\n```python\nresult = await match_util.sequence_query(sequence_query=sequence_query)\n```\n___\n+ Run a specific query, lets delete everything\n```python\nawait database_operations.run_query(query=f\"match (n) detach delete n\")\n```\n\n\n\n### Not Implemented\n\n+ Update a node\n___\n+ Update a sequence\n___\n+ Delete a node\n___\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "",
"version": "0.3.7",
"project_urls": {
"Homepage": "https://github.com/Michaelzag/PydanticNeo4j",
"Repository": "https://github.com/Michaelzag/PydanticNeo4j"
},
"split_keywords": [
"neo4j-pydantic",
"pydantic",
"neo4j",
"ogm",
"neo4j-og",
"michaelzag"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9095c89ab49b62879475ed779ea7849a2f88199253fc9621b12b4b007b301459",
"md5": "9c673ff020b0a33e6e5b6e1677c4ee80",
"sha256": "25c2b1c5094e60f36a764d397cb7d281b2a04ab22cba93c9809ada34c1744bf2"
},
"downloads": -1,
"filename": "pydantic_neo4j-0.3.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9c673ff020b0a33e6e5b6e1677c4ee80",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11,<4.0",
"size": 9895,
"upload_time": "2023-08-17T14:26:16",
"upload_time_iso_8601": "2023-08-17T14:26:16.769032Z",
"url": "https://files.pythonhosted.org/packages/90/95/c89ab49b62879475ed779ea7849a2f88199253fc9621b12b4b007b301459/pydantic_neo4j-0.3.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7255e3e87beecc6c61545fb7972f3b0665239bd4e1c86c443354981cbfd46a8d",
"md5": "783ced4a167c1355feaf2dbf6895e69c",
"sha256": "1c58b1a97ebbe7116481f736b4dc992776120f7d867d80d13d7e9ee263c566c2"
},
"downloads": -1,
"filename": "pydantic_neo4j-0.3.7.tar.gz",
"has_sig": false,
"md5_digest": "783ced4a167c1355feaf2dbf6895e69c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11,<4.0",
"size": 7784,
"upload_time": "2023-08-17T14:26:17",
"upload_time_iso_8601": "2023-08-17T14:26:17.963293Z",
"url": "https://files.pythonhosted.org/packages/72/55/e3e87beecc6c61545fb7972f3b0665239bd4e1c86c443354981cbfd46a8d/pydantic_neo4j-0.3.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-17 14:26:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Michaelzag",
"github_project": "PydanticNeo4j",
"github_not_found": true,
"lcname": "pydantic-neo4j"
}