Skip to main content

A modern, Pythonic ORM for TypeDB with an Attribute-based API

Project description

TypeBridge

A modern, Pythonic ORM for TypeDB with an Attribute-based API that aligns with TypeDB's type system.

Features

  • True TypeDB Semantics: Attributes are independent types that entities and relations own
  • Type-Safe: Full Python type hints and IDE autocomplete support
  • Declarative Models: Define entities and relations using Python classes
  • Automatic Schema Generation: Generate TypeQL schemas from your Python models
  • CRUD Operations: Simple managers for entity and relation operations
  • Query Builder: Pythonic interface for building TypeQL queries
  • Clean API: No Pydantic conflicts, simple dict-based value storage

Installation

# Clone the repository
git clone https://github.com/yourusername/type_bridge.git
cd type_bridge

# Install with uv
uv sync

# Or with pip
pip install -e .

Quick Start

1. Define Attribute Types

from type_bridge import String, Long

class Name(String):
    pass

class Age(Long):
    pass

2. Define Entities

from type_bridge import Annotated, Entity, EntityFlags, Flag, Key, Card

class Person(Entity):
    flags = EntityFlags(type_name="person")  # Optional, defaults to lowercase class name

    # Two equivalent syntaxes - choose your preference:

    # Style 1: Using Annotated (Pydantic-style, more explicit)
    name: Annotated[Name, Flag(Key, Card(1))]
    age: Annotated[Age, Flag(Card(0, 1))]

    # Style 2: Using default value (cleaner, but less explicit in type hints)
    # name: Name = Flag(Key, Card(1))
    # age: Age = Flag(Card(0, 1))

3. Work with Data

from type_bridge import Database, SchemaManager, EntityManager

# Setup
db = Database(address="localhost:1729", database="mydb")
schema_manager = SchemaManager(db)
schema_manager.register(Person)
schema_manager.sync_schema(force=True)

# CRUD
person_manager = EntityManager(db, Person)
alice = person_manager.create(name="Alice", age=30)
all_people = person_manager.all()

4. Cardinality Constraints

from type_bridge import Card

# Card semantics:
Card(1)          # @card(1,1) - exactly one
Card(min=0)      # @card(0) - zero or more (unbounded)
Card(max=5)      # @card(1,5) - one to five
Card(1, 3)       # @card(1,3) - one to three
Card(0, 5)       # @card(0,5) - zero to five

5. Using Python Inheritance

class Animal(Entity):
    flags = EntityFlags(abstract=True)  # Abstract entity
    name: Name

class Dog(Animal):  # Automatically: dog sub animal in TypeDB
    breed: Breed

Documentation

See ATTRIBUTE_API.md for complete documentation.

Running Examples

uv run python examples/basic_usage.py

Running Tests

uv run pytest tests/ -v

Requirements

  • Python 3.13+
  • TypeDB 2.x or 3.x
  • typedb-driver==3.5.5

License

MIT License

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

type_bridge-0.1.2.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

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

type_bridge-0.1.2-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file type_bridge-0.1.2.tar.gz.

File metadata

  • Download URL: type_bridge-0.1.2.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for type_bridge-0.1.2.tar.gz
Algorithm Hash digest
SHA256 84706f364f04a0870dca142d4f72aa74a3970205029d2527495aa0483108513b
MD5 7273797af9f9c2cc66b7aab319e3c6b6
BLAKE2b-256 5a39dd7ebbbbe604513bab75251132ef0ad98a434838ea84efdf70ba214f9363

See more details on using hashes here.

File details

Details for the file type_bridge-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: type_bridge-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for type_bridge-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b6f03c3f04bfae889b28f3088c2f81e67b4b9a3c5d8e368846d55ecdb8237f9f
MD5 62c58d4f4c18d780324e8dc2255adef7
BLAKE2b-256 cc4d54f8aa2e697e710dab15b12da683673f965307662788f7292b523bd95b4a

See more details on using hashes here.

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