Context
Context for the current dataset pipeline
Bases: BaseModel
Source code in investigraph/model/context.py
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 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 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 | |
cache
property
A shared cache instance
dataset
property
The dataset name (identifier)
log
property
A structlog dataset logging instance for the runtime
prefix
property
The dataset id prefix (defaults to its name)
store
cached
property
The statement store instance to write fragments to
export(*args, **kwargs)
Execute the configured export handler.
Defaults to investigraph.logic.export:handle
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset model instance for the pipeline dataset, with computed stats if configured. |
Source code in investigraph/model/context.py
extract_all(limit=None)
Extract all records from all sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int | None
|
Optionally only return this number of items per source (for debugging purposes) |
None
|
Yields:
| Type | Description |
|---|---|
RecordGenerator
|
Generator of dictionaries |
Source code in investigraph/model/context.py
get_sources(limit=None)
Get all the instances of
SourceContext for the
current pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int | None
|
Optionally only return this number of items (for debugging purposes) |
None
|
Yields:
| Type | Description |
|---|---|
SourceContext
|
Generator for Source model instances |
Source code in investigraph/model/context.py
load(proxies, *args, **kwargs)
Load transformed records with the configured handler.
Defaults to investigraph.logic.load:handle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proxies
|
StatementEntities
|
Generator of StatementEntity instances |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of entities loaded to store |
Source code in investigraph/model/context.py
make_entity(schema, *args, **kwargs)
Instantiate a new Entity with its schema and optional data.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
str
|
required |
Returns:
| Type | Description |
|---|---|
StatementEntity
|
instance of StatementEntity |
Source code in investigraph/model/context.py
make_fingerprint_id(*args, **kwargs)
Generate an ID (usable for an entity ID). This guarantees a valid slug
or raises an error. It either uses the configured dataset prefix or a
custom prefix given as prefix keyword argument. The ID is generated
from the fingerprint (using rigour.fingerprints) of the arguments as a
SHA1 hash (same as followthemoney.util.make_entity_id)
Returns:
| Type | Description |
|---|---|
str
|
An ID based on the fingerprints of the input values |
Raises:
| Type | Description |
|---|---|
ValueError
|
When the id is invalid (e.g. empty string or |
Source code in investigraph/model/context.py
make_id(*args, **kwargs)
Generate an ID (usable for an entity ID). This guarantees a valid slug
or raises an error. It either uses the configured dataset prefix or a
custom prefix given as prefix keyword argument. The ID is generated
from the arguments as a SHA1 hash (same as
followthemoney.util.make_entity_id)
Returns:
| Type | Description |
|---|---|
str
|
An ID |
Raises:
| Type | Description |
|---|---|
ValueError
|
When the id is invalid (e.g. empty string or |
Source code in investigraph/model/context.py
make_slug(*args, **kwargs)
Generate a slug (usable for an entity ID). This guarantees a valid slug
or raises an error. It either uses the configured dataset prefix or a
custom prefix given as prefix keyword argument.
Returns:
| Type | Description |
|---|---|
str
|
A slug |
Raises:
| Type | Description |
|---|---|
ValueError
|
When the slug is invalid (e.g. empty string or |
Source code in investigraph/model/context.py
Context for the current source
Bases: DatasetContext
Source code in investigraph/model/context.py
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 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
extract_key
cached
property
The computed cache ke for extraction for the current source. See Cache
should_extract
cached
property
Check if the source with the same cache key was already extracted
extract(limit=None)
Extract the records for the current source with the configured handler.
Defaults to investigraph.logic.extract:handle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int | None
|
Optionally only return this number of items per source (for debugging purposes) |
None
|
Yields:
| Type | Description |
|---|---|
RecordGenerator
|
Generator of dictionaries |
Source code in investigraph/model/context.py
open(mode=DEFAULT_MODE, **kwargs)
Open the context source as a file-like handler. If archive=True is set
via extract stage config, the source will be downloaded locally first.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str | None
|
The mode to open, defaults |
DEFAULT_MODE
|
Returns:
| Type | Description |
|---|---|
ContextManager[IO[AnyStr]]
|
A file-handler like context manager. The file gets closed when leaving the context. |
Source code in investigraph/model/context.py
task()
Get a runtime task context to pass on to helper functions within
transform stage. See TaskContext.emit
Example
Returns:
| Type | Description |
|---|---|
TaskContext
|
The runtime task context |
Source code in investigraph/model/context.py
transform(records)
Transform extracted records from the current source into FollowTheMoney
entities with the configured handler.
Defaults to investigraph.logic.transform:map_ftm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
RecordGenerator
|
Generator of record items as |
required |
Yields:
| Type | Description |
|---|---|
StatementEntities
|
Generator of StatementEntity |
Source code in investigraph/model/context.py
Runtime task context
Bases: SourceContext
Source code in investigraph/model/context.py
emit(*proxies)
Emit Entity instances during task runtime. The entities will already be merged. This is useful for helper functions within transform logic that create multiple entities "on the fly"