CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-neomodel

An object mapper for the neo4j graph database.

Pending
Overview
Eval results
Files

properties.mddocs/

Property Types

Comprehensive set of typed properties for node and relationship attributes in neomodel. Properties provide type validation, database constraints, indexing support, and data transformation between Python and Neo4j formats.

Capabilities

Basic Property Types

Fundamental property types for common data storage needs.

class Property:
    """
    Abstract base class for all property types.
    
    Args:
        required (bool): Property must have a value (default: False)
        unique_index (bool): Create unique constraint (default: False)
        index (bool): Create database index (default: False)
        default: Default value or callable
    """
    def __init__(self, required=False, unique_index=False, index=False, default=None, **kwargs): ...

class StringProperty(Property):
    """
    Unicode string property with optional validation and constraints.
    
    Args:
        max_length (int, optional): Maximum string length
        choices (list, optional): List of allowed values
        **kwargs: Base property arguments
    """
    def __init__(self, max_length=None, choices=None, **kwargs): ...

class IntegerProperty(Property):
    """
    Integer value property.
    
    Args:
        **kwargs: Base property arguments
    """
    def __init__(self, **kwargs): ...

class FloatProperty(Property):
    """
    Floating point value property.
    
    Args:
        **kwargs: Base property arguments
    """
    def __init__(self, **kwargs): ...

class BooleanProperty(Property):
    """
    Boolean value property.
    
    Args:
        **kwargs: Base property arguments
    """
    def __init__(self, **kwargs): ...

class ArrayProperty(Property):
    """
    List/array property with optional base type constraints.
    
    Args:
        base_property (Property, optional): Property type for array elements
        **kwargs: Base property arguments
    """
    def __init__(self, base_property=None, **kwargs): ...

class JSONProperty(Property):
    """
    JSON data structure property for complex nested data.
    
    Args:
        **kwargs: Base property arguments
    """
    def __init__(self, **kwargs): ...

Specialized Properties

Properties with built-in validation and formatting logic.

class AliasProperty(Property):
    """
    Property that aliases another property name.
    
    Args:
        to (str): Name of the target property to alias
        **kwargs: Base property arguments
    """
    def __init__(self, to=None, **kwargs): ...

class UniqueIdProperty(Property):
    """
    Auto-generated UUID4 identifier property.
    
    Automatically generates unique identifiers when nodes are created.
    
    Args:
        **kwargs: Base property arguments
    """
    def __init__(self, **kwargs): ...

class EmailProperty(StringProperty):
    """
    Email address property with regex validation.
    
    Args:
        **kwargs: StringProperty arguments
    """
    def __init__(self, **kwargs): ...

class RegexProperty(StringProperty):
    """
    String property with custom regex validation.
    
    Args:
        expression (str): Regular expression pattern for validation
        **kwargs: StringProperty arguments
    """
    def __init__(self, expression=None, **kwargs): ...

class NormalizedProperty(Property):
    """
    Base class for properties that normalize values.
    
    Args:
        **kwargs: Base property arguments
    """
    def __init__(self, **kwargs): ...

Date and Time Properties

Properties for temporal data storage and manipulation.

class DateProperty(Property):
    """
    Date storage property (date objects only, no time component).
    
    Args:
        **kwargs: Base property arguments
    """
    def __init__(self, **kwargs): ...

class DateTimeProperty(Property):
    """
    DateTime property stored as Unix epoch timestamp.
    
    Args:
        default_now (bool): Set default to current timestamp (default: False)
        **kwargs: Base property arguments
    """
    def __init__(self, default_now=False, **kwargs): ...

class DateTimeFormatProperty(Property):
    """
    DateTime property with custom string format.
    
    Args:
        format (str): strftime format string
        **kwargs: Base property arguments
    """
    def __init__(self, format=None, **kwargs): ...

class DateTimeNeo4jFormatProperty(Property):
    """
    DateTime property using Neo4j's native datetime format.
    
    Args:
        **kwargs: Base property arguments
    """
    def __init__(self, **kwargs): ...

Index Types

Specialized index configurations for advanced querying capabilities.

class FulltextIndex:
    """
    Configuration for fulltext search indexes.
    
    Args:
        analyzer (str, optional): Text analyzer to use
        eventually_consistent (bool): Index consistency mode
    """
    def __init__(self, analyzer=None, eventually_consistent=True): ...

class VectorIndex:
    """
    Configuration for vector similarity indexes.
    
    Args:
        dimensions (int): Vector dimensionality
        similarity_function (str): Similarity metric ('cosine', 'euclidean')
    """
    def __init__(self, dimensions=None, similarity_function='cosine'): ...

Spatial Properties

Spatial data types for working with Neo4j's spatial data types with Shapely integration. Requires the optional shapely dependency.

class NeomodelPoint:
    """
    Spatial point data type with Shapely integration.
    
    Supports both Cartesian and WGS-84 coordinate systems in 2D and 3D.
    
    Args:
        x (float, optional): X coordinate for Cartesian points
        y (float, optional): Y coordinate for Cartesian points
        z (float, optional): Z coordinate for 3D Cartesian points
        longitude (float, optional): Longitude for WGS-84 points
        latitude (float, optional): Latitude for WGS-84 points
        height (float, optional): Height for 3D WGS-84 points
        crs (str, optional): Coordinate reference system
                           ('cartesian', 'cartesian-3d', 'wgs-84', 'wgs-84-3d')
    """
    def __init__(self, *args, crs=None, x=None, y=None, z=None, 
                 latitude=None, longitude=None, height=None, **kwargs): ...
    
    @property
    def crs(self) -> str: ...
    
    @property
    def x(self) -> float: ...  # For Cartesian points
    
    @property
    def y(self) -> float: ...  # For Cartesian points
    
    @property
    def z(self) -> float: ...  # For 3D Cartesian points
    
    @property
    def latitude(self) -> float: ...  # For WGS-84 points
    
    @property
    def longitude(self) -> float: ...  # For WGS-84 points
    
    @property
    def height(self) -> float: ...  # For 3D WGS-84 points

class PointProperty(Property):
    """
    Property for spatial points with coordinate reference system validation.
    
    Args:
        crs (str): Required coordinate reference system
                  ('cartesian', 'cartesian-3d', 'wgs-84', 'wgs-84-3d')
        **kwargs: Base property arguments
    """
    def __init__(self, crs, **kwargs): ...

Usage Examples

Basic Property Usage

from neomodel import (
    StructuredNode, StringProperty, IntegerProperty, 
    BooleanProperty, ArrayProperty, JSONProperty
)

class Product(StructuredNode):
    # Basic properties
    name = StringProperty(required=True, unique_index=True)
    price = FloatProperty(required=True)
    in_stock = BooleanProperty(default=True)
    
    # String with constraints
    category = StringProperty(
        choices=['electronics', 'books', 'clothing'],
        index=True
    )
    
    # Array and JSON properties
    tags = ArrayProperty(StringProperty(), default=list)
    metadata = JSONProperty(default=dict)

# Create product with properties
product = Product(
    name="Laptop",
    price=999.99,
    category="electronics",
    tags=["computer", "portable"],
    metadata={"brand": "TechCorp", "warranty": "2 years"}
).save()

Specialized Properties

from neomodel import (
    StructuredNode, EmailProperty, UniqueIdProperty,
    DateTimeProperty, RegexProperty
)

class User(StructuredNode):
    # Auto-generated unique ID
    user_id = UniqueIdProperty()
    
    # Email validation
    email = EmailProperty(unique_index=True, required=True)
    
    # Custom regex validation
    phone = RegexProperty(
        expression=r'^\+?1?\d{9,15}$',
        required=False
    )
    
    # Timestamp properties
    created_at = DateTimeProperty(default_now=True)
    last_login = DateTimeProperty()

# Create user
user = User(
    email="user@example.com",
    phone="+1234567890"
).save()

Spatial Properties Usage

from neomodel import StructuredNode, StringProperty, PointProperty
from neomodel.contrib.spatial_properties import NeomodelPoint

class Location(StructuredNode):
    name = StringProperty(required=True)
    
    # Cartesian coordinate point
    position = PointProperty(crs='cartesian')
    
    # WGS-84 geographic point
    coordinates = PointProperty(crs='wgs-84')

# Create locations with spatial data
warehouse = Location(
    name="Warehouse",
    position=NeomodelPoint(x=100.0, y=200.0, crs='cartesian'),
    coordinates=NeomodelPoint(longitude=-122.4194, latitude=37.7749, crs='wgs-84')  # San Francisco
).save()

# Create 3D spatial points
building = Location(
    name="Tower",
    position=NeomodelPoint(x=50.0, y=75.0, z=100.0, crs='cartesian-3d')
).save()

# Access spatial properties
print(f"Warehouse longitude: {warehouse.coordinates.longitude}")
print(f"Building height: {building.position.z}")

Advanced Indexing

from neomodel import StructuredNode, StringProperty, FulltextIndex

class Article(StructuredNode):
    title = StringProperty(required=True)
    content = StringProperty(index=FulltextIndex(analyzer='english'))
    tags = ArrayProperty(StringProperty(), index=True)

# Search using fulltext index
articles = Article.nodes.filter(content__search='machine learning')

Property Validation and Constraints

from neomodel import StructuredNode, StringProperty, IntegerProperty

class Person(StructuredNode):
    # Required property
    name = StringProperty(required=True)
    
    # Unique constraint
    ssn = StringProperty(unique_index=True)
    
    # Choice constraint
    status = StringProperty(
        choices=['active', 'inactive', 'pending'],
        default='active'
    )
    
    # Length constraint
    bio = StringProperty(max_length=500)

# This will raise validation errors if constraints are violated
try:
    person = Person(name="", status="invalid").save()  # Empty required field and invalid choice
except Exception as e:
    print(f"Validation error: {e}")

Types

# Property constraint types
PropertyConstraint = Union[str, int, float, bool, list, dict]
PropertyChoice = Union[str, int, float]
PropertyDefault = Union[PropertyConstraint, Callable[[], PropertyConstraint]]

# Index types
IndexType = Union[bool, FulltextIndex, VectorIndex]

Install with Tessl CLI

npx tessl i tessl/pypi-neomodel

docs

database.md

exceptions.md

index.md

nodes.md

properties.md

queries.md

relationships.md

tile.json