Resource Data Sources
Resource data sources load tabular data from CKAN resources. They are used automatically by the Resource View feature but can also be instantiated manually when you need to build a table backed by a resource file or the Datastore.
All file-based sources extend BaseResourceDataSource, which handles source path resolution (local upload vs. remote URL) and pluggable caching. The CKAN Datastore source (DataStoreDataSource) is separate and queries the Datastore API directly without any caching.
File-based sources
CsvUrlDataSource
Reads a CSV file from a local path or remote URL. The delimiter is detected automatically.
from ckanext.tables.shared import CsvUrlDataSource
# From a direct URL
source = CsvUrlDataSource(url="https://example.com/data.csv")
# From a CKAN resource dict (resolves upload path automatically)
source = CsvUrlDataSource(resource=resource_dict)
Source code in ckanext/tables/data_sources.py
414 415 416 417 418 419 420 | |
XlsxUrlDataSource
Reads the first sheet of an Excel workbook (.xlsx).
from ckanext.tables.shared import XlsxUrlDataSource
source = XlsxUrlDataSource(url="https://example.com/report.xlsx")
Source code in ckanext/tables/data_sources.py
423 424 425 426 427 428 429 | |
OrcUrlDataSource
Reads an Apache ORC columnar file.
from ckanext.tables.shared import OrcUrlDataSource
source = OrcUrlDataSource(url="https://example.com/data.orc")
Source code in ckanext/tables/data_sources.py
432 433 434 435 436 437 438 | |
ParquetUrlDataSource
Reads an Apache Parquet columnar file.
from ckanext.tables.shared import ParquetUrlDataSource
source = ParquetUrlDataSource(url="https://example.com/data.parquet")
Source code in ckanext/tables/data_sources.py
441 442 443 444 445 446 447 | |
FeatherUrlDataSource
Reads an Apache Arrow Feather file.
from ckanext.tables.shared import FeatherUrlDataSource
source = FeatherUrlDataSource(url="https://example.com/data.feather")
Source code in ckanext/tables/data_sources.py
450 451 452 453 454 455 456 | |
Caching
All file-based sources inherit from BaseResourceDataSource, which caches the fetched DataFrame to avoid re-downloading on every request. The cache backend and TTL are controlled globally via configuration (see Configuration):
ckanext.tables.cache.backend = pickle # or "redis"
ckanext.tables.cache.pickle.cache_dir = /var/cache/ckanext-tables
You can override the backend or TTL per instance:
from ckanext.tables.shared import CsvUrlDataSource, RedisCacheBackend
source = CsvUrlDataSource(
url="https://example.com/data.csv",
cache_backend=RedisCacheBackend(),
cache_ttl=120, # seconds
)
A data source that loads resource data from a file or URL.
The cache backend defaults to the value of ckanext.tables.cache.backend
("pickle" by default). Pass an explicit cache_backend to
override for a specific instance.
Override cache_ttl on a subclass or pass it to the constructor to
change the expiry.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
Direct URL to fetch data from.
TYPE:
|
resource
|
The CKAN resource dictionary.
TYPE:
|
cache_backend
|
Override the configured cache backend for this instance.
TYPE:
|
cache_ttl
|
Override the default TTL (seconds) for this instance.
TYPE:
|
Source code in ckanext/tables/data_sources.py
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 | |
DataStoreDataSource
Queries the CKAN Datastore API directly. This source is used automatically when a resource has datastore_active = True. It does not use any caching, as the data is already stored in the database.
from ckanext.tables.shared import DataStoreDataSource
source = DataStoreDataSource(resource_id="<resource-id>")
Filtering, sorting, and pagination are translated into datastore_search parameters:
=→ exact match filterlike→ full-text search (partial word match via PostgreSQL FTS with:*)- Other comparison operators are not supported by
datastore_searchand are silently ignored.
Note
DataStoreDataSource requires the datastore plugin to be enabled in CKAN. If it is not active, all methods return empty results gracefully.
A data source that fetches records directly from the CKAN Datastore.
Source code in ckanext/tables/data_sources.py
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 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |