No project description provided
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ckanext_collection-0.2.1.tar.gz
.
File metadata
- Download URL: ckanext_collection-0.2.1.tar.gz
- Upload date:
- Size: 83.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.0.0 pkginfo/1.10.0 requests/2.32.3 setuptools/75.1.0 requests-toolbelt/1.0.0 tqdm/4.66.6 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f01876045eb032aeec8bd6c2de4bc6a41f88669f4e7fe0e4a896fc79723541c |
|
MD5 | 0563002a24fc05a5168aaf9370051d2c |
|
BLAKE2b-256 | 9feb5d2004fa667baf7538f7f851fbb91b898d3e22c47f81b1dcedc1d15db96c |
File details
Details for the file ckanext_collection-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: ckanext_collection-0.2.1-py3-none-any.whl
- Upload date:
- Size: 102.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.0.0 pkginfo/1.10.0 requests/2.32.3 setuptools/75.1.0 requests-toolbelt/1.0.0 tqdm/4.66.6 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dae8d2e48a49f353d0cea0cfd56c1833e5603b7a48d28c3fde5180bca87f4e87 |
|
MD5 | 3d9a11dd943c338c9af7321aab3d50e9 |
|
BLAKE2b-256 | ce2ab37fdab597de49a7c891033d22f4ff0d85861d2eaaee3e5c524e158e6c26 |