ckanext-collection
Tools for building interfaces for data collections using declarative style.
This extension simplifies describing series of items, such as datasets from search page, users registered on portal, rows of CSV file, tables in DB, etc. Once you defined the way of fetching items from data source, you'll get generic interface for pagination, search and displaying data in any format: HTML page, CSV document, JSON list, or any other custom format that you can describe.
Read the documentation for a full user guide.
Quickstart
Install the extension
pip install ckanext-collection
Add collection to the ckan.plugins setting in your CKAN config file
Define the collection
from ckan import model
from ckanext.collection.shared import collection, data, columns, serialize
## collection of all resources from DB
class MyCollection(collection.Collection):
DataFactory = data.ModelData.with_attributes(model=model.Resource)
# `names` controls names of fields exported by serializer
# further in this guide
ColumnsFactory = columns.Columns.with_attributes(names=["name", "size"])
## collection of all packages available via search API
class MyCollection(collection.Collection):
DataFactory = data.ApiSearchData.with_attributes(action="package_search")
ColumnsFactory = columns.Columns.with_attributes(names=["name", "title"])
## collection of all records from CSV file
class MyCollection(collection.Collection):
DataFactory = data.CsvFileData.with_attributes(source="/path/to/file.csv")
ColumnsFactory = columns.Columns.with_attributes(names=["a", "b"])
Initialize collection object and work with data:
# collection with first page of results(1st-10th items)
col = MyCollection()
items = list(col)
# collection with third page of results(21st-30th items)
col = MyCollection("", {"page": 3})
items = list(col)
# alternatively, read all the items into memory at once, without pagination.
# It may be quite expensive operation depending on number of items
col = MyCollection()
items = list(col.data)
# or get the slice of data from 8th till 12th
items = list(col.data[8:12])
# check total number of items in collection
print(col.data.total)
Serialize data using Serializer service:
# JSON string
serializer = serialize.JsonSerializer(col)
# or CSV string
serializer = serialize.CsvSerializer(col)
# or python list of dictionaries
serializer = serialize.DictListSerializer(col)
print(serializer.serialize())
License
Metadata
Release files for ckanext-collection 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ckanext_collection-0.3.0.tar.gz | 85.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ckanext_collection-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 187.8 kB
Release files / ckanext_collection-0.3.0.tar.gz
| Download URL | ckanext_collection-0.3.0.tar.gz |
|---|---|
| Size | 85.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
437932ca32dd91038575d1c36eefc5974b6b8aebc5f7dbe9640becafb05fb09c
|
|
BLAKE2b-256 checksum How to use checksums |
2976dbfe994e07330d9edb90ce372ca6d21dc9424d51b879a0442808d4ec7c91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Release files / ckanext_collection-0.3.0-py3-none-any.whl
| Download URL | ckanext_collection-0.3.0-py3-none-any.whl |
|---|---|
| Size | 102.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd7e2aa4c5693442a4abc554b210ae34abe163c0aa1b8285714ef176ff68e7df
|
|
BLAKE2b-256 checksum How to use checksums |
f05d6b590e1fe8877f97faa72513efda896e4978a27fbccee77e77d179fce095
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.19
|
Security for ckanext-collection 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.