Name | ckanext-collection JSON |
Version |
0.2.1
JSON |
| download |
home_page | None |
Summary | None |
upload_time | 2024-11-10 15:19:07 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | AGPL |
keywords |
ckan
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
|
[![Tests](https://github.com/DataShades/ckanext-collection/workflows/Tests/badge.svg?branch=main)](https://github.com/DataShades/ckanext-collection/actions)
# 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](https://datashades.github.io/ckanext-collection/) for
a full user guide.
## Quickstart
Install the extension
```sh
pip install ckanext-collection
```
Add `collection` to the `ckan.plugins` setting in your CKAN config file
Define the collection
```python
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:
```python
# 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:
```python
# 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
[AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html)
Raw data
{
"_id": null,
"home_page": null,
"name": "ckanext-collection",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "DataShades <datashades@linkdigital.com.au>",
"keywords": "CKAN",
"author": null,
"author_email": "DataShades <datashades@linkdigital.com.au>, Sergey Motornyuk <sergey.motornyuk@linkdigital.com.au>",
"download_url": "https://files.pythonhosted.org/packages/9f/eb/5d2004fa667baf7538f7f851fbb91b898d3e22c47f81b1dcedc1d15db96c/ckanext_collection-0.2.1.tar.gz",
"platform": null,
"description": "[![Tests](https://github.com/DataShades/ckanext-collection/workflows/Tests/badge.svg?branch=main)](https://github.com/DataShades/ckanext-collection/actions)\n\n# ckanext-collection\n\nTools for building interfaces for data collections using declarative style.\n\nThis extension simplifies describing series of items, such as datasets from\nsearch page, users registered on portal, rows of CSV file, tables in DB,\netc. Once you defined the way of fetching items from data source, you'll get\ngeneric interface for pagination, search and displaying data in any format:\nHTML page, CSV document, JSON list, or any other custom format that you can\ndescribe.\n\nRead the [documentation](https://datashades.github.io/ckanext-collection/) for\na full user guide.\n\n\n## Quickstart\n\nInstall the extension\n\n```sh\npip install ckanext-collection\n```\n\nAdd `collection` to the `ckan.plugins` setting in your CKAN config file\n\nDefine the collection\n\n```python\nfrom ckan import model\nfrom ckanext.collection.shared import collection, data, columns, serialize\n\n\n## collection of all resources from DB\nclass MyCollection(collection.Collection):\n DataFactory = data.ModelData.with_attributes(model=model.Resource)\n # `names` controls names of fields exported by serializer\n # further in this guide\n ColumnsFactory = columns.Columns.with_attributes(names=[\"name\", \"size\"])\n\n## collection of all packages available via search API\nclass MyCollection(collection.Collection):\n DataFactory = data.ApiSearchData.with_attributes(action=\"package_search\")\n ColumnsFactory = columns.Columns.with_attributes(names=[\"name\", \"title\"])\n\n## collection of all records from CSV file\nclass MyCollection(collection.Collection):\n DataFactory = data.CsvFileData.with_attributes(source=\"/path/to/file.csv\")\n ColumnsFactory = columns.Columns.with_attributes(names=[\"a\", \"b\"])\n\n```\n\nInitialize collection object and work with data:\n\n```python\n\n# collection with first page of results(1st-10th items)\ncol = MyCollection()\nitems = list(col)\n\n# collection with third page of results(21st-30th items)\ncol = MyCollection(\"\", {\"page\": 3})\nitems = list(col)\n\n\n# alternatively, read all the items into memory at once, without pagination.\n# It may be quite expensive operation depending on number of items\ncol = MyCollection()\nitems = list(col.data)\n\n# or get the slice of data from 8th till 12th\nitems = list(col.data[8:12])\n\n# check total number of items in collection\nprint(col.data.total)\n\n```\n\nSerialize data using `Serializer` service:\n\n```python\n\n# JSON string\nserializer = serialize.JsonSerializer(col)\n\n# or CSV string\nserializer = serialize.CsvSerializer(col)\n\n# or python list of dictionaries\nserializer = serialize.DictListSerializer(col)\n\n\nprint(serializer.serialize())\n\n```\n\n## License\n\n[AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html)\n",
"bugtrack_url": null,
"license": "AGPL",
"summary": null,
"version": "0.2.1",
"project_urls": {
"Homepage": "https://github.com/DataShades/ckanext-collection"
},
"split_keywords": [
"ckan"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ce2ab37fdab597de49a7c891033d22f4ff0d85861d2eaaee3e5c524e158e6c26",
"md5": "3d9a11dd943c338c9af7321aab3d50e9",
"sha256": "dae8d2e48a49f353d0cea0cfd56c1833e5603b7a48d28c3fde5180bca87f4e87"
},
"downloads": -1,
"filename": "ckanext_collection-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3d9a11dd943c338c9af7321aab3d50e9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 102319,
"upload_time": "2024-11-10T15:19:05",
"upload_time_iso_8601": "2024-11-10T15:19:05.337404Z",
"url": "https://files.pythonhosted.org/packages/ce/2a/b37fdab597de49a7c891033d22f4ff0d85861d2eaaee3e5c524e158e6c26/ckanext_collection-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9feb5d2004fa667baf7538f7f851fbb91b898d3e22c47f81b1dcedc1d15db96c",
"md5": "0563002a24fc05a5168aaf9370051d2c",
"sha256": "5f01876045eb032aeec8bd6c2de4bc6a41f88669f4e7fe0e4a896fc79723541c"
},
"downloads": -1,
"filename": "ckanext_collection-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "0563002a24fc05a5168aaf9370051d2c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 83735,
"upload_time": "2024-11-10T15:19:07",
"upload_time_iso_8601": "2024-11-10T15:19:07.792079Z",
"url": "https://files.pythonhosted.org/packages/9f/eb/5d2004fa667baf7538f7f851fbb91b898d3e22c47f81b1dcedc1d15db96c/ckanext_collection-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-10 15:19:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "DataShades",
"github_project": "ckanext-collection",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "ckanext-collection"
}