Skip to main content

No project description provided

Project description

loomi

CI Python Version License: MIT

A minimalistic Python Object-Graph Mapper designed to handle the most common tasks when working with Neo4j or Memgraph.

Features

  • Hybrid Sync/Async Architecture: Built around the driver provided by the neo4j, loomi supports both sync and async clients.
  • Dual-Database Support: Compatibility with both Neo4j and Memgraph out of the box.
  • Type Safety: Fully typed models and queries thanks to pydantic.
  • Compatibility out of the box: Drop-in replacement when you already use the driver provided by the neo4j package. Enable additional features as required.

Installation

Install via pip or your favorite package manager:

pip install loomi

Or with poetry:

poetry add loomi

Quick start

1. Define your schema

from loomi import Node, Relationship
from pydantic import Field

class Child(Node):
  name: str
  age: int

  # Define how the node is displayed in the database
  loomi_config = {
    "labels": {"Human", "Child"}
  }


class Adult(Node):
  name: str
  age: int
  job: str


class FamilyRelation(Relationship):
  loves_child: bool = Field(default=True)

  # Define how the relationship is displayed in the database
  loomi_config = {
    "type": "IS_PARENT_OF"
  }

2. Connect and query

import asyncio
import neo4j
from loomi import AsyncClient

# Initialize the driver like usual
driver = neo4j.AsyncGraphDatabase.driver(
  uri="bolt://localhost:7687", auth=("neo4j", "password")
)
client = AsyncClient(driver)

# Register models which the client should resolve
client.register(Child, Adult, FamilyRelation)

async def main():
  await client.initialize()

  async with client.session() as session:
    # Create some sample data
    await session.run(
      "CREATE (a:Adult $adult)-[r:IS_PARENT_OF $relation]->(c:Human:Child $child)",
      {
        "adult": {
          "name": "John",
          "age": 28,
          "job": "Developer"
        },
        "child": {
          "name": "Holly",
          "age": 5,
        },
        "relation": {
          "loves_child": True
        }
      }
    )

    # Query the database like you would usually
    result = await session.run(
      "MATCH (a:Adult)-[r:IS_PARENT_OF]->(c:Human:Child) RETURN a, c"
    )

    # `result` provides the same interface as the native result
    # with some loomi-specific additions
    models = await result.values()

    # Prints [[<Adult element_id='...' labels={'Adult'}>, <Child element_id='...' labels={'Child', 'Human'}>]]
    print(models)


if __name__ == "__main__":
  asyncio.run(main())

Local development & testing

This project uses Poetry to manage dependencies and virtual environments.

1. Setup environment

git clone [https://github.com/yourusername/loomi.git](https://github.com/yourusername/loomi.git)
cd loomi

poetry install
poetry run pre-commit install

2. Run database containers

docker compose up -d

3. Run the test suite

poetry run pytest tests/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loomi-1.0.0.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loomi-1.0.0-py3-none-any.whl (57.0 kB view details)

Uploaded Python 3

File details

Details for the file loomi-1.0.0.tar.gz.

File metadata

  • Download URL: loomi-1.0.0.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for loomi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7b5ed06b47450951142f89b54762f069a044f97d14eb6a1925f3ac47cb798eae
MD5 37f3c7696102c52564751bbeca313475
BLAKE2b-256 bdf84c6f8771dd1b34983b2459ee884b83bae1fccd883be1a2c8652d90e39894

See more details on using hashes here.

Provenance

The following attestation bundles were made for loomi-1.0.0.tar.gz:

Publisher: release.yml on groc-prog/loomi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file loomi-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: loomi-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 57.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for loomi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4fd026ddcd2700f078165873f1eab7ff3bb4bbb7d33835eab9043b5cdd27f67
MD5 317bbfe9f5da97987576fcad25864207
BLAKE2b-256 5e0a063a3f7da4ba4923e2fd2644ab273236c148c7765a6a99b92e01c6f7dbbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for loomi-1.0.0-py3-none-any.whl:

Publisher: release.yml on groc-prog/loomi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page