uni-pydantic
Pydantic-based OGM (Object-Graph Mapping) for the Uni Graph Database.
Features
- Type Safety: Full IDE autocomplete and type checking for graph operations.
- Pydantic v2: Leverage Pydantic's validation, computed fields, and serialization.
- Schema-from-Models: Auto-generate Uni schema from Pydantic model definitions.
- Relationships: Edges as declarative fields with direction support.
- Query DSL: Type-safe filter builder with raw Cypher escape hatch.
- Vector Search: Built-in K-NN similarity search.
- Lifecycle Hooks:
@before_create,@after_createdecorators.
Installation
pip install uni-pydantic
Quick Start
import uni_db
from uni_pydantic import UniNode, UniEdge, UniSession, Field, Relationship, Vector
# Define models
class Person(UniNode):
__label__ = "Person"
name: str
age: int | None = None
email: str = Field(unique=True, index="btree")
embedding: Vector[128] = Field(metric="cosine")
friends: list["Person"] = Relationship("FRIEND_OF", direction="both")
class Company(UniNode):
__label__ = "Company"
name: str = Field(unique=True)
class WorksAt(UniEdge):
__edge_type__ = "WORKS_AT"
__from__ = Person
__to__ = Company
role: str = "engineer"
# Connect and sync schema
db = uni_db.Uni("./my_graph")
session = UniSession(db)
session.register(Person, Company, WorksAt)
session.sync_schema()
# Create
alice = Person(name="Alice", age=30, email="alice@example.com")
session.add(alice)
session.commit()
# Query with DSL
adults = (
session.query(Person)
.filter(Person.age >= 18)
.order_by(Person.name)
.limit(10)
.all()
)
# Vector search
similar = (
session.query(Person)
.vector_search("embedding", query_vector, k=10)
.all()
)
Model Definition
Nodes
from uni_pydantic import UniNode, Field, Vector
class Article(UniNode):
__label__ = "Article" # optional — defaults to class name
title: str
slug: str = Field(index="btree", unique=True)
views: int = Field(default=0)
tags: list[str] = Field(default_factory=list)
embedding: Vector[768] = Field(metric="cosine")
Edges
from uni_pydantic import UniEdge
class Authored(UniEdge):
__edge_type__ = "AUTHORED"
__from__ = Person
__to__ = Article
role: str = "primary"
Relationships
class Person(UniNode):
follows: list["Person"] = Relationship("FOLLOWS")
followers: list["Person"] = Relationship("FOLLOWS", direction="incoming")
friends: list["Person"] = Relationship("FRIEND_OF", direction="both")
manager: "Person | None" = Relationship("REPORTS_TO")
Query DSL
# Filter
people = session.query(Person).filter(Person.name == "Alice").all()
# Chained
results = (
session.query(Person)
.filter(Person.age >= 18)
.order_by(Person.name, descending=True)
.limit(10)
.skip(20)
.all()
)
# Filter helpers
Person.name.starts_with("A")
Person.name.contains("lic")
Person.age.in_([25, 30, 35])
Person.email.is_null()
Person.email.is_not_null()
# Vector search
similar = (
session.query(Person)
.vector_search("embedding", query_vec, k=10)
.all()
)
CRUD
# Create
person = Person(name="Bob", age=25)
session.add(person)
session.commit()
# Bulk
session.add_all([Person(name=f"User{i}") for i in range(100)])
session.commit()
# Update
person.age = 26
session.commit()
# Delete
session.delete(person)
session.commit()
Lifecycle Hooks
from datetime import datetime
from uni_pydantic import before_create, after_create
class Person(UniNode):
name: str
created_at: datetime | None = None
@before_create
def set_created_at(self):
self.created_at = datetime.now()
@after_create
def log_creation(self):
print(f"Created: {self.name}")
Raw Cypher
results = session.cypher(
"MATCH (p:Person)-[:FRIEND_OF]->(f:Person) WHERE p.name = $name RETURN f",
params={"name": "Alice"},
result_type=Person,
)
Async
from uni_pydantic import AsyncUniSession
session = AsyncUniSession(db)
await session.sync_schema()
alice = Person(name="Alice", email="alice@example.com")
session.add(alice)
await session.commit()
results = await session.query(Person).filter(Person.age >= 18).all()
Links
License
Apache-2.0
Metadata
Release files for uni-pydantic 4.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| uni_pydantic-4.1.1.tar.gz | 230.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| uni_pydantic-4.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 281.4 kB
Release files / uni_pydantic-4.1.1.tar.gz
| Download URL | uni_pydantic-4.1.1.tar.gz |
|---|---|
| Size | 230.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8d7dd062346bb04c0cb30f581e11974ef868423af13cf61b293189dcf6aaba9
|
|
BLAKE2b-256 checksum How to use checksums |
6a897024fcdf6623d00a2e29704525e09a36acf66103b1b0d9beb48ddf40c226
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / uni_pydantic-4.1.1-py3-none-any.whl
| Download URL | uni_pydantic-4.1.1-py3-none-any.whl |
|---|---|
| Size | 51.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0b9fde9161ffb6a67c06c1063a89efb998b03a60a764809c907e979605ab5015
|
|
BLAKE2b-256 checksum How to use checksums |
75b6e91f14974684d9a54041bb0d23feb58a4fef30a90cf9a5d8f200d16be553
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for uni-pydantic 4.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.