Metadata-Version: 2.3
Name: followthemoney-neomodel
Version: 0.1.0
Summary: Models followthemoney Schemas into neomodel ogm classes
License: Apache-2.0
Author: Justin Quick
Author-email: justin.quick@c4ads.org
Requires-Python: >=3.10
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Database
Requires-Dist: followthemoney
Requires-Dist: neomodel
Description-Content-Type: text/markdown

# followthemoney-neomodel

Models [followthemoney](https://followthemoney.tech/) Schemas into [neomodel](https://neomodel.readthedocs.io/en/latest/) ogm classes

On the fly creation of classes for nodes and edges based on follow the money schema

Classes can be directly imported and used to create objects in a neo4j graph and traverse the graph

# Setup

Requires followthemoney and neomodel. Any version of followthemoney will work as

`pip install followthemoney-neomodel`

This takes any version of followthemoney and will model whatever schemas are defined in that version

# Usage

## Basic

Just import and use classes directly to create objects

```python
from followthemoney_neomodel import Person, Vehicle

# create two edges based on Person and Vehicle schema
me = Person(name='me')
me.save()

car = Vehicle(name='honda')
car.save()

# connect the two nodes together with edge OWNERSHIP relation and properties
me.owns.connect(car, {'role': 'lease'})
```

The module also has a `models` dict that you can use instead of importing to reference all models created

```python
from followthemoney_neomodel import models

me = models['Person'](name='me')
```


```python
Person.nodes.traverse("owns__name").all()
```

## Async

Want async support? The modeler also sets up matching `Async*` classes

```python
from followthemoney_neomodel import AsyncPerson

async def main():
    me = Person(name='me')
    await me.save()

    car = Vehicle(name='honda')
    await car.save()

    await me.owns.connect(car, {'role': 'lease'})
```


## Output

Generates a simple graph

![sample graph](./readme.png)

Then you can query the graph using traversal syntax from neomodel

# Testing

Run these tests on a dev neo4j instance/database as it will create nodes/edges which can pollute your graph.

Set `NEOMODEL_DATABASE_URL` env var to define destination db for testing

```bash
git clone ...
cd followthemoney-neomodel
poetry install -G dev
poetry run pytest tests.py
```
