0
# Property Types
1
2
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.
3
4
## Capabilities
5
6
### Basic Property Types
7
8
Fundamental property types for common data storage needs.
9
10
```python { .api }
11
class Property:
12
"""
13
Abstract base class for all property types.
14
15
Args:
16
required (bool): Property must have a value (default: False)
17
unique_index (bool): Create unique constraint (default: False)
18
index (bool): Create database index (default: False)
19
default: Default value or callable
20
"""
21
def __init__(self, required=False, unique_index=False, index=False, default=None, **kwargs): ...
22
23
class StringProperty(Property):
24
"""
25
Unicode string property with optional validation and constraints.
26
27
Args:
28
max_length (int, optional): Maximum string length
29
choices (list, optional): List of allowed values
30
**kwargs: Base property arguments
31
"""
32
def __init__(self, max_length=None, choices=None, **kwargs): ...
33
34
class IntegerProperty(Property):
35
"""
36
Integer value property.
37
38
Args:
39
**kwargs: Base property arguments
40
"""
41
def __init__(self, **kwargs): ...
42
43
class FloatProperty(Property):
44
"""
45
Floating point value property.
46
47
Args:
48
**kwargs: Base property arguments
49
"""
50
def __init__(self, **kwargs): ...
51
52
class BooleanProperty(Property):
53
"""
54
Boolean value property.
55
56
Args:
57
**kwargs: Base property arguments
58
"""
59
def __init__(self, **kwargs): ...
60
61
class ArrayProperty(Property):
62
"""
63
List/array property with optional base type constraints.
64
65
Args:
66
base_property (Property, optional): Property type for array elements
67
**kwargs: Base property arguments
68
"""
69
def __init__(self, base_property=None, **kwargs): ...
70
71
class JSONProperty(Property):
72
"""
73
JSON data structure property for complex nested data.
74
75
Args:
76
**kwargs: Base property arguments
77
"""
78
def __init__(self, **kwargs): ...
79
```
80
81
### Specialized Properties
82
83
Properties with built-in validation and formatting logic.
84
85
```python { .api }
86
class AliasProperty(Property):
87
"""
88
Property that aliases another property name.
89
90
Args:
91
to (str): Name of the target property to alias
92
**kwargs: Base property arguments
93
"""
94
def __init__(self, to=None, **kwargs): ...
95
96
class UniqueIdProperty(Property):
97
"""
98
Auto-generated UUID4 identifier property.
99
100
Automatically generates unique identifiers when nodes are created.
101
102
Args:
103
**kwargs: Base property arguments
104
"""
105
def __init__(self, **kwargs): ...
106
107
class EmailProperty(StringProperty):
108
"""
109
Email address property with regex validation.
110
111
Args:
112
**kwargs: StringProperty arguments
113
"""
114
def __init__(self, **kwargs): ...
115
116
class RegexProperty(StringProperty):
117
"""
118
String property with custom regex validation.
119
120
Args:
121
expression (str): Regular expression pattern for validation
122
**kwargs: StringProperty arguments
123
"""
124
def __init__(self, expression=None, **kwargs): ...
125
126
class NormalizedProperty(Property):
127
"""
128
Base class for properties that normalize values.
129
130
Args:
131
**kwargs: Base property arguments
132
"""
133
def __init__(self, **kwargs): ...
134
```
135
136
### Date and Time Properties
137
138
Properties for temporal data storage and manipulation.
139
140
```python { .api }
141
class DateProperty(Property):
142
"""
143
Date storage property (date objects only, no time component).
144
145
Args:
146
**kwargs: Base property arguments
147
"""
148
def __init__(self, **kwargs): ...
149
150
class DateTimeProperty(Property):
151
"""
152
DateTime property stored as Unix epoch timestamp.
153
154
Args:
155
default_now (bool): Set default to current timestamp (default: False)
156
**kwargs: Base property arguments
157
"""
158
def __init__(self, default_now=False, **kwargs): ...
159
160
class DateTimeFormatProperty(Property):
161
"""
162
DateTime property with custom string format.
163
164
Args:
165
format (str): strftime format string
166
**kwargs: Base property arguments
167
"""
168
def __init__(self, format=None, **kwargs): ...
169
170
class DateTimeNeo4jFormatProperty(Property):
171
"""
172
DateTime property using Neo4j's native datetime format.
173
174
Args:
175
**kwargs: Base property arguments
176
"""
177
def __init__(self, **kwargs): ...
178
```
179
180
### Index Types
181
182
Specialized index configurations for advanced querying capabilities.
183
184
```python { .api }
185
class FulltextIndex:
186
"""
187
Configuration for fulltext search indexes.
188
189
Args:
190
analyzer (str, optional): Text analyzer to use
191
eventually_consistent (bool): Index consistency mode
192
"""
193
def __init__(self, analyzer=None, eventually_consistent=True): ...
194
195
class VectorIndex:
196
"""
197
Configuration for vector similarity indexes.
198
199
Args:
200
dimensions (int): Vector dimensionality
201
similarity_function (str): Similarity metric ('cosine', 'euclidean')
202
"""
203
def __init__(self, dimensions=None, similarity_function='cosine'): ...
204
```
205
206
### Spatial Properties
207
208
Spatial data types for working with Neo4j's spatial data types with Shapely integration. Requires the optional `shapely` dependency.
209
210
```python { .api }
211
class NeomodelPoint:
212
"""
213
Spatial point data type with Shapely integration.
214
215
Supports both Cartesian and WGS-84 coordinate systems in 2D and 3D.
216
217
Args:
218
x (float, optional): X coordinate for Cartesian points
219
y (float, optional): Y coordinate for Cartesian points
220
z (float, optional): Z coordinate for 3D Cartesian points
221
longitude (float, optional): Longitude for WGS-84 points
222
latitude (float, optional): Latitude for WGS-84 points
223
height (float, optional): Height for 3D WGS-84 points
224
crs (str, optional): Coordinate reference system
225
('cartesian', 'cartesian-3d', 'wgs-84', 'wgs-84-3d')
226
"""
227
def __init__(self, *args, crs=None, x=None, y=None, z=None,
228
latitude=None, longitude=None, height=None, **kwargs): ...
229
230
@property
231
def crs(self) -> str: ...
232
233
@property
234
def x(self) -> float: ... # For Cartesian points
235
236
@property
237
def y(self) -> float: ... # For Cartesian points
238
239
@property
240
def z(self) -> float: ... # For 3D Cartesian points
241
242
@property
243
def latitude(self) -> float: ... # For WGS-84 points
244
245
@property
246
def longitude(self) -> float: ... # For WGS-84 points
247
248
@property
249
def height(self) -> float: ... # For 3D WGS-84 points
250
251
class PointProperty(Property):
252
"""
253
Property for spatial points with coordinate reference system validation.
254
255
Args:
256
crs (str): Required coordinate reference system
257
('cartesian', 'cartesian-3d', 'wgs-84', 'wgs-84-3d')
258
**kwargs: Base property arguments
259
"""
260
def __init__(self, crs, **kwargs): ...
261
```
262
263
## Usage Examples
264
265
### Basic Property Usage
266
267
```python
268
from neomodel import (
269
StructuredNode, StringProperty, IntegerProperty,
270
BooleanProperty, ArrayProperty, JSONProperty
271
)
272
273
class Product(StructuredNode):
274
# Basic properties
275
name = StringProperty(required=True, unique_index=True)
276
price = FloatProperty(required=True)
277
in_stock = BooleanProperty(default=True)
278
279
# String with constraints
280
category = StringProperty(
281
choices=['electronics', 'books', 'clothing'],
282
index=True
283
)
284
285
# Array and JSON properties
286
tags = ArrayProperty(StringProperty(), default=list)
287
metadata = JSONProperty(default=dict)
288
289
# Create product with properties
290
product = Product(
291
name="Laptop",
292
price=999.99,
293
category="electronics",
294
tags=["computer", "portable"],
295
metadata={"brand": "TechCorp", "warranty": "2 years"}
296
).save()
297
```
298
299
### Specialized Properties
300
301
```python
302
from neomodel import (
303
StructuredNode, EmailProperty, UniqueIdProperty,
304
DateTimeProperty, RegexProperty
305
)
306
307
class User(StructuredNode):
308
# Auto-generated unique ID
309
user_id = UniqueIdProperty()
310
311
# Email validation
312
email = EmailProperty(unique_index=True, required=True)
313
314
# Custom regex validation
315
phone = RegexProperty(
316
expression=r'^\+?1?\d{9,15}$',
317
required=False
318
)
319
320
# Timestamp properties
321
created_at = DateTimeProperty(default_now=True)
322
last_login = DateTimeProperty()
323
324
# Create user
325
user = User(
326
email="user@example.com",
327
phone="+1234567890"
328
).save()
329
```
330
331
### Spatial Properties Usage
332
333
```python
334
from neomodel import StructuredNode, StringProperty, PointProperty
335
from neomodel.contrib.spatial_properties import NeomodelPoint
336
337
class Location(StructuredNode):
338
name = StringProperty(required=True)
339
340
# Cartesian coordinate point
341
position = PointProperty(crs='cartesian')
342
343
# WGS-84 geographic point
344
coordinates = PointProperty(crs='wgs-84')
345
346
# Create locations with spatial data
347
warehouse = Location(
348
name="Warehouse",
349
position=NeomodelPoint(x=100.0, y=200.0, crs='cartesian'),
350
coordinates=NeomodelPoint(longitude=-122.4194, latitude=37.7749, crs='wgs-84') # San Francisco
351
).save()
352
353
# Create 3D spatial points
354
building = Location(
355
name="Tower",
356
position=NeomodelPoint(x=50.0, y=75.0, z=100.0, crs='cartesian-3d')
357
).save()
358
359
# Access spatial properties
360
print(f"Warehouse longitude: {warehouse.coordinates.longitude}")
361
print(f"Building height: {building.position.z}")
362
```
363
364
### Advanced Indexing
365
366
```python
367
from neomodel import StructuredNode, StringProperty, FulltextIndex
368
369
class Article(StructuredNode):
370
title = StringProperty(required=True)
371
content = StringProperty(index=FulltextIndex(analyzer='english'))
372
tags = ArrayProperty(StringProperty(), index=True)
373
374
# Search using fulltext index
375
articles = Article.nodes.filter(content__search='machine learning')
376
```
377
378
### Property Validation and Constraints
379
380
```python
381
from neomodel import StructuredNode, StringProperty, IntegerProperty
382
383
class Person(StructuredNode):
384
# Required property
385
name = StringProperty(required=True)
386
387
# Unique constraint
388
ssn = StringProperty(unique_index=True)
389
390
# Choice constraint
391
status = StringProperty(
392
choices=['active', 'inactive', 'pending'],
393
default='active'
394
)
395
396
# Length constraint
397
bio = StringProperty(max_length=500)
398
399
# This will raise validation errors if constraints are violated
400
try:
401
person = Person(name="", status="invalid").save() # Empty required field and invalid choice
402
except Exception as e:
403
print(f"Validation error: {e}")
404
```
405
406
## Types
407
408
```python { .api }
409
# Property constraint types
410
PropertyConstraint = Union[str, int, float, bool, list, dict]
411
PropertyChoice = Union[str, int, float]
412
PropertyDefault = Union[PropertyConstraint, Callable[[], PropertyConstraint]]
413
414
# Index types
415
IndexType = Union[bool, FulltextIndex, VectorIndex]
416
```