Layer 3: Repository
Domain-specific combinations of multiple stores. Each repository owns one domain concept.
ArchiveRepository
Content-addressed file archive with metadata and extracted text storage.
ftm_lakehouse.repository.ArchiveRepository
Bases: BaseRepository
Repository for file archive operations.
Combines content-addressed blob storage (raw bytes) and model-based metadata storage (JSON) to provide file archiving.
Blobs are stored once per checksum, but each unique source path creates its own metadata file (keyed by File.id).
Optionally, extracted text (by different origins) can be stored and retrieved. As well, other programs can write arbitrary additional data to the archive (such as pdf page thumbnails).
Example
Source code in ftm_lakehouse/repository/archive.py
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 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 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 | |
delete(file)
Delete a file's metadata from the archive.
The blob is never deleted. (FIXME)
Source code in ftm_lakehouse/repository/archive.py
exists(checksum)
get_all_files(checksum)
Iterate all metadata files for the given checksum.
Multiple crawlers may have archived the same file content from different source paths, each creating their own metadata file.
Source code in ftm_lakehouse/repository/archive.py
get_data(checksum, path)
get_file(checksum, file_id=None)
Get file metadata for the given checksum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checksum
|
str
|
SHA256 checksum of file |
required |
file_id
|
str | None
|
Optional File.id to get specific metadata |
None
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When no metadata file exists |
Source code in ftm_lakehouse/repository/archive.py
get_txt(checksum, origin=None)
Get extracted text for a file. If origin, get by this specific
extraction, otherwise get the first txt value (no guaranteed order)
Source code in ftm_lakehouse/repository/archive.py
iterate_files()
local_path(checksum)
Get the local path to the blob.
If storage is local, returns actual path. Otherwise, creates a temporary local copy that is cleaned up after context exit.
Source code in ftm_lakehouse/repository/archive.py
open(checksum)
put_data(checksum, path, data)
put_file(file)
put_txt(checksum, text, origin=DEFAULT_ORIGIN)
Store extracted text for a file.
store(uri, file=None, checksum=None, **metadata)
Archive a file from a local or remote URI.
The blob is stored once per checksum, but each unique source path creates its own metadata file (keyed by File.id).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
Local or remote URI to the file |
required |
file
|
File | None
|
Optional metadata file object to patch |
None
|
checksum
|
str | None
|
Content hash (skip computation if provided) |
None
|
**metadata
|
Any
|
Additional data to store in file's extra field, including
FollowTheMoney properties for the |
{}
|
Returns:
| Type | Description |
|---|---|
File
|
File metadata object |
Source code in ftm_lakehouse/repository/archive.py
store_blob(uri, checksum=None)
Store bytes blob from given uri if it doesn't exist yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Uri
|
Local or remote URI to the file |
required |
checksum
|
str | None
|
Content hash (skip computation if provided) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
checksum |
Source code in ftm_lakehouse/repository/archive.py
stream(checksum)
write_blob(fh, checksum=None)
Write a blob from the given open file-handler
Source code in ftm_lakehouse/repository/archive.py
EntityRepository
Entity/statement operations combining JournalStore and ParquetStore.
dataset.entities.add(entity, origin="import")
dataset.entities.writer(origin="import")
dataset.entities.flush()
dataset.entities.query(origin="import")
ftm_lakehouse.repository.EntityRepository
Bases: ParquetDiffMixin, BaseRepository, ApiEntityRepository
Repository for entity/statement operations.
Combines JournalStore (write-ahead buffer) and ParquetStore (Delta Lake) to provide buffered statement storage with efficient querying.
Writes go to the journal first, then are flushed to the parquet store. Reads query the parquet store (optionally flushing first).
Example
Source code in ftm_lakehouse/repository/entities/main.py
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 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 338 339 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 395 396 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 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
version
property
Current version of the main Delta table.
add(entity, origin=None)
add_many(entities, origin=None)
Add an entity iterator to the journal.
Source code in ftm_lakehouse/repository/entities/main.py
delete_entity(entity_id)
Delete all statements for an entity via journal tombstones.
Reads statements from both parquet and journal, then UPSERTs tombstone rows (with deleted_at set) into the journal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
The entity ID to delete |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of tombstone statements written |
Source code in ftm_lakehouse/repository/entities/main.py
delete_statement(stmt)
Delete a single statement via journal tombstone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stmt
|
Statement
|
The Statement to delete |
required |
Source code in ftm_lakehouse/repository/entities/main.py
export_entities(output_uri)
Export entities to a JSON lines file without FtM object construction.
Uses query_raw() / aggregate_unsafe() to bypass Statement/StatementEntity/to_dict() and writes directly to orjson output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_uri
|
str
|
Destination URI for the entities.ftm.json file |
required |
Source code in ftm_lakehouse/repository/entities/main.py
flush()
Flush statements from journal to parquet store.
Uses dedup logic: - New statements (not in main table): append to main + insert into translog - Duplicate statements (already in main): update translog last_seen only - Tombstones (deleted_at set): update translog deleted_at only
Returns:
| Type | Description |
|---|---|
int
|
Number of new statements flushed to the main table |
Source code in ftm_lakehouse/repository/entities/main.py
get(entity_id, origin=None, flush_first=False)
Get a single entity by ID.
Source code in ftm_lakehouse/repository/entities/main.py
get_statistics()
query(entity_ids=None, flush_first=False, **filters)
Query entities from the parquet store.
Additional filter kwargs are passed to ftmq Query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_ids
|
Iterable[str] | None
|
Filter by entity IDs |
None
|
flush_first
|
bool
|
Flush journal before querying (default False) |
False
|
Yields:
| Type | Description |
|---|---|
StatementEntities
|
StatementEntity objects matching the query |
Source code in ftm_lakehouse/repository/entities/main.py
stream()
Stream entities from the exported JSON file.
This reads from the pre-exported entities.ftm.json file, not directly from the parquet store.
Source code in ftm_lakehouse/repository/entities/main.py
writer(origin=None)
Get a bulk writer for adding entities/statements.
Usage
with repo.writer(origin="import") as writer: writer.add_entity(entity)
Source code in ftm_lakehouse/repository/entities/main.py
MappingRepository
Mapping configuration storage.
ftm_lakehouse.repository.MappingRepository
Bases: BaseRepository
Repository for mapping configuration storage.
Combines FileStore (current configs) and VersionStore (snapshots) to provide versioned mapping configuration storage.
Each mapping is identified by a content_hash (SHA1 of the source CSV file).
Example
Source code in ftm_lakehouse/repository/mapping.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 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 | |
delete(content_hash)
Delete a mapping configuration.
exists(content_hash)
get(content_hash)
Get a mapping configuration by content hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_hash
|
str
|
SHA1 checksum of the source CSV file |
required |
Returns:
| Type | Description |
|---|---|
DatasetMapping
|
DatasetMapping if exists, None otherwise |
Source code in ftm_lakehouse/repository/mapping.py
iterate()
list()
List all content hashes that have mapping configurations.
Yields:
| Type | Description |
|---|---|
str
|
Content hash strings for files with mapping.yml configs |
Source code in ftm_lakehouse/repository/mapping.py
put(mapping)
Store a mapping configuration.
Creates both a current config and a versioned snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
DatasetMapping
|
The mapping configuration to store |
required |
Returns:
| Type | Description |
|---|---|
str
|
The current version path |
Source code in ftm_lakehouse/repository/mapping.py
JobRepository
Job tracking and status.
ftm_lakehouse.repository.JobRepository
Bases: BaseRepository, Generic[J]
Repository for job run storage.
Persists job run data as JSON files, organized by job type and run ID.
Example
repo = JobRepository(dataset="my_data", uri="s3://bucket/dataset")
# Store a job run
repo.put(job)
# Get latest run for a job type
job = repo.latest(CrawlJob)
# Run a job with lifecycle management
with repo.run(job) as run:
# Do work...
run.save() # Periodic save
# Job automatically stopped when context exits
Source code in ftm_lakehouse/repository/job.py
delete(job)
get(run_id)
iterate()
latest()
Get the latest run for the configured job type (self.model).
Jobs are sorted by run ID (which contains timestamp), so the latest is the last in alphabetical order.
Source code in ftm_lakehouse/repository/job.py
put(job)
run(job)
Get a context manager for running a job.
The job is automatically started on entry and stopped on exit. If an exception occurs, it's recorded in the job's exc field.