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 Entity, EntityFlags, Flag, Key, Card

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

    name: Name = Flag(Key, Card(1))  # Person owns 'name' as @key @card(1,1)
    age: Age = Flag(Card(0, 1))      # Person owns 'age' as @card(0,1) - optional

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.1.tar.gz (33.5 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.1-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: type_bridge-0.1.1.tar.gz
  • Upload date:
  • Size: 33.5 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.1.tar.gz
Algorithm Hash digest
SHA256 0a0cb5f00117b992bbb4b1c4d5b8688284c002df6aab7ed0d54d59116deff1ca
MD5 dc289eb62c4edd4ac3f0645b633040e2
BLAKE2b-256 dec6ea2fdbb1e2703ce0845ec984b0332c3464dcd2acd6486748374c853514c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: type_bridge-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e2b309de5a7b75b302d97f672ce7bca039bb0979be4c44c792f8a16d465e124
MD5 fe7158312f3d0b78ac3a0e12770c3deb
BLAKE2b-256 19fde1e17e02bbbf9f857c4d2951f95ae9e9fdca46d82fd53a5378240cff08e8

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