ORM
Utilities for working with Notion as an ORM.
There are two primary constructs in this module that enable custom type definitions
in Notional: Property()
and connected_page()
.
ConnectedPage
Base class for "live" pages via the Notion API.
All changes are committed in real time.
Source code in src/notional/orm.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
children
property
Return an iterator for all child blocks of this Page.
cover
property
writable
Return the cover for the Page.
icon
property
writable
Return the icon for the Page.
id
property
Return the ID of this page (if available).
__iadd__(block)
Append the given block to this page.
This operation takes place on the Notion server, causing the page to save immediately.
Source code in src/notional/orm.py
246 247 248 249 250 251 252 253 254 255 |
|
__init__(page)
Construct a ConnectedPage using the underlying Page object.
Source code in src/notional/orm.py
177 178 179 180 181 182 183 |
|
__init_subclass__(database=None, **kwargs)
Register new subclasses of a ConnectedPage.
Source code in src/notional/orm.py
185 186 187 188 189 190 191 192 193 |
|
append(*blocks)
Append the given blocks as children of this ConnectedPage.
This operation takes place on the Notion server, causing the page to update immediately.
Source code in src/notional/orm.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
bind(to_session)
classmethod
Attach this ConnectedPage to the given session.
Setting this to None will detach the page.
Source code in src/notional/orm.py
276 277 278 279 280 281 282 283 |
|
create(**kwargs)
classmethod
Create a new instance of the ConnectedPage type.
Any properties that support object composition may be defined in kwargs
.
This operation takes place on the Notion server, creating the page immediately.
:param kwargs: the properties to initialize for this object as parameters, i.e.
name=value
, where name
is the attribute in the custom type and value
is
a supported type for composing.
Source code in src/notional/orm.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
parse_obj(obj)
classmethod
Parse the given object as a ConnectedPage.
Similar to BaseModel.parse_obj(data)
.
Source code in src/notional/orm.py
331 332 333 334 335 336 337 |
|
query()
classmethod
Return a QueryBuilder
for the custom type.
Source code in src/notional/orm.py
285 286 287 288 289 290 291 292 293 294 295 |
|
ConnectedPageFactory
A factory that builds custom types for ConnectedPage
classes.
Typically, these generated classes will be extended to form a custom type.
Source code in src/notional/orm.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
|
__call__(session, database, schema=None)
Return a new type from this factory with the given configuration.
Source code in src/notional/orm.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
|
__init__(name='CustomBase', base=None, metaclass=None)
Initialize the ConnectedPageFactory
with the given parameters.
:param name: the name of the class generated by this factory; defaults to "CustomBase"
:param base: the class (or tuple of classes) used as the base class for types
generated by this factory; defaults to None
:param metaclass: the callable metaclass to use for generating new types;
defaults to type
Source code in src/notional/orm.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
ConnectedProperty
Contains the information and methods needed for a connected property.
When created, this object does not have a reference to its parent object. Before
this property is accessed for the first time, callers must use bind()
to set the
containing object at runtime.
Source code in src/notional/orm.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
__init__(name, schema, default=...)
Initialize the property wrapper.
:param name: the name of this property as it appears on Notional
:param schema: the PropertyObject that defines the type of this property
:param default: an optional parameter that will return a default value if one is not provided by the API
Source code in src/notional/orm.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
bind(obj)
Binds this property to the given object.
Source code in src/notional/orm.py
62 63 64 65 66 67 68 69 70 71 72 |
|
delete()
Delete the value associated with this property.
Source code in src/notional/orm.py
117 118 119 120 121 122 123 124 125 126 |
|
get()
Return the current value of the property as a python object.
Source code in src/notional/orm.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
set(value)
Set the property to the given value.
Source code in src/notional/orm.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
Property(name, schema=None, default=...)
Define a property for a Notion Page object.
Internally, this method uses a custom wrapper to manage the property methods.
:param name: the Notion table property name :param schema: the schema that defines this property (default = RichText) :param default: a default value when creating new objects
Source code in src/notional/orm.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
connected_page(session=None, source_db=None, schema=None, cls=None)
Return a base class for "connected" pages through the Notion API.
Subclasses may then inherit from the returned class to define custom ORM types.
:param session: an active Notional session where the database is hosted
:param source_db: if provided, the returned class will use the ID and schema of this object to initialize the connected page
:param schema: if provided, the returned class will contain properties according
to the schema provided; defaults to None
:param cls: the returned class will inherit from the given class, which must be a
subclass of ConnectedPage
; defaults to ConnectedPage
Source code in src/notional/orm.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
|