Core
Base classes for working with the Notion API.
ComposableObjectMeta
Bases:
Presents a metaclass that composes objects using simple values.
This is primarily to allow easy definition of data objects without disrupting the
BaseModel
constructor. e.g. rather than requiring a caller to understand how
nested data works in the data objects, they can compose objects from simple values.
Compare the following code for declaring a Paragraph:
# using nested data objects:
text = "hello world"
nested = TextObject._NestedData(content=text)
rtf = text.TextObject(text=nested, plain_text=text)
content = blocks.Paragraph._NestedData(text=[rtf])
para = blocks.Paragraph(paragraph=content)
# using a composable object:
para = blocks.Paragraph["hello world"]
Classes that support composition in this way must define and implement the internal
__compose__
method. This method takes an arbitrary number of parameters, based
on the needs of the implementation. It is up to the implementing class to ensure
that the parameters are specified correctly.
Source code in src/notional/core.py
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 |
|
__getitem__(params)
Return the requested class by composing using the given param.
Types found in params
will be compared to expected types in the __compose__
method.
If the requested class does not expose the __compose__
method, this will raise
an exception.
Source code in src/notional/core.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
GenericObject
Bases:
The base for all API objects.
As a general convention, data fields in lower case are defined by the Notion API. Properties in Title Case are provided for convenience.
Source code in src/notional/core.py
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 127 128 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 169 170 |
|
__setattr__(name, value)
Set the attribute of this object to a given value.
The implementation of BaseModel.__setattr__
does not support property setters.
See https://github.com/samuelcolvin/pydantic/issues/1577
Source code in src/notional/core.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
dict(**kwargs)
Convert to a suitable representation for the Notion API.
Source code in src/notional/core.py
158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
refresh(__notional_self__, **data)
Refresh the internal attributes with new data.
Source code in src/notional/core.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
NotionObject
Bases:
A top-level Notion API resource.
Source code in src/notional/core.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
__init_subclass__(object=None, **kwargs)
Update GenericObject
defaults for the named object.
Source code in src/notional/core.py
179 180 181 182 183 184 |
|
TypedObject
Bases:
A type-referenced object.
Many objects in the Notion API follow a standard pattern with a 'type' property
followed by additional data. These objects must specify a type
attribute to
ensure that the correct object is created.
For example, this contains a nested 'detail' object:
data = {
type: "detail",
...
detail: {
...
}
}
Calling the object provides direct access to the data stored in {type}
.
Source code in src/notional/core.py
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 |
|
__call__(field=None)
Return the nested data object contained by this TypedObject
.
If a field is provided, the contents of that field in the nested data will be returned. Otherwise, the full contents of the NestedData will be returned.
Source code in src/notional/core.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
__get_validators__()
classmethod
Provide BaseModel
with the means to convert TypedObject
's.
Source code in src/notional/core.py
248 249 250 251 |
|
__init_subclass__(type=None, **kwargs)
Register the subtypes of the TypedObject subclass.
Source code in src/notional/core.py
221 222 223 224 225 226 227 |
|
parse_obj(obj)
classmethod
Parse the structured object data into an instance of TypedObject
.
This method overrides BaseModel.parse_obj()
.
Source code in src/notional/core.py
253 254 255 256 257 258 259 |
|
serialize_to_api(data)
Recursively convert the given data to an API-safe form.
This is mostly to handle data types that will not directly serialize to JSON.
Source code in src/notional/core.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|