CKAN¶
CKAN plugin provides Package and Resource models and converters between CKAN and Data Package notations
Installation¶
Not extra dependencies are required
Usage¶
Converting a CKAN descriptor to the Data Package notation:
from dplib.plugins.ckan.models import CkanPackage
package = CkanPackage.from_path("data/plugins/ckan/package.json").to_dp()
print(package.to_text(format='json'))
{
"resources": [
{
"name": "sample_linked",
"path": "sample-linked.csv",
"format": "csv",
"mediatype": "text/csv",
"ckan:id": "e687245d-7835-44b0-8ed3-0827de123895"
},
{
"name": "sample",
"path": "sample.csv",
"format": "csv",
"mediatype": "application/csv",
"bytes": 6731,
"ckan:id": "b53c9e72-6b59-4cda-8c0c-7d6a51dad12a"
},
{
"name": "views",
"path": "views.csv",
"format": "csv",
"bytes": 32773,
"ckan:id": "9ce6650b-6ff0-4a52-9b10-09cfc29bbd7e"
},
{
"name": "sample",
"path": "sample.pdf",
"format": "pdf",
"bytes": 712352,
"ckan:id": "8aa53505-3b7f-4b9c-9b54-cf674eadc3f1"
},
{
"name": "sample",
"path": "sample.txt",
"format": "txt",
"bytes": 85,
"ckan:id": "0185907b-2812-437f-9c64-eae24771ef5f"
},
{
"name": "sample",
"path": "sample.geojson",
"format": "geojson",
"bytes": 255943,
"ckan:id": "ecd4a62d-998b-46e4-8a64-cadac2125c64"
},
{
"name": "sample",
"path": "sample.kml",
"format": "kml",
"bytes": 474000,
"ckan:id": "048333ab-9608-42dc-901b-a7dd9fca3dda"
},
{
"name": "avoid_crowds_when_buying_materials_social_media_post",
"path": "avoid-crowds-when-buying-materials-social-media-post.jpeg",
"format": "jpeg",
"mediatype": "image/png",
"bytes": 444695,
"ckan:id": "b6c22c1d-e789-490d-b935-989093bbb173"
},
{
"name": "sample_wms",
"path": "Sample WMS",
"format": "wms",
"ckan:id": "664e5e2c-bd7d-4972-a245-a747f7d61cc9"
}
],
"name": "sample-dataset-1",
"title": "Sample Dataset",
"description": "A CKAN Dataset is a collection of data resources (such as files), together with a description and other information (what is known as metadata), at a fixed URL. \r\n\r\n",
"version": "1.0",
"licenses": [
{
"name": "cc-by",
"title": "Creative Commons Attribution",
"url": "http://www.opendefinition.org/licenses/cc-by"
}
],
"contributors": [
{
"title": "Test Author",
"email": "test@email.com",
"role": "author"
},
{
"title": "Test Maintainer",
"email": "test@email.com",
"role": "maintainer"
}
],
"keywords": [
"csv",
"economy",
"geojson",
"kml",
"pdf",
"sample",
"txt",
"wms"
],
"created": "2021-04-09T11:39:37.657233",
"ckan:id": "c322307a-b871-44fe-a602-32ee8437ff04"
}
Converting a Data Package to CKAN notation:
from dplib.models import Package
from dplib.plugins.ckan.models import CkanPackage
package = CkanPackage.from_dp(Package.from_path("data/package.json"))
print(package.to_text(format="json"))
Reference¶
dplib.plugins.ckan.models.CkanPackage
¶
Bases: Model
CKAN Package model
Source code in dplib/plugins/ckan/models/package.py
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 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 |
|
author: Optional[str] = None
class-attribute
instance-attribute
¶
author_email: Optional[str] = None
class-attribute
instance-attribute
¶
id: Optional[str] = None
class-attribute
instance-attribute
¶
license_id: Optional[str] = None
class-attribute
instance-attribute
¶
license_title: Optional[str] = None
class-attribute
instance-attribute
¶
license_url: Optional[str] = None
class-attribute
instance-attribute
¶
maintainer: Optional[str] = None
class-attribute
instance-attribute
¶
maintainer_email: Optional[str] = None
class-attribute
instance-attribute
¶
metadata_created: Optional[str] = None
class-attribute
instance-attribute
¶
metadata_modified: Optional[str] = None
class-attribute
instance-attribute
¶
name: Optional[str] = None
class-attribute
instance-attribute
¶
notes: Optional[str] = None
class-attribute
instance-attribute
¶
organization: Optional[CkanOrganization] = None
class-attribute
instance-attribute
¶
resources: List[CkanResource] = []
class-attribute
instance-attribute
¶
tags: List[CkanTag] = []
class-attribute
instance-attribute
¶
title: Optional[str] = None
class-attribute
instance-attribute
¶
version: Optional[str] = None
class-attribute
instance-attribute
¶
from_dp(package)
classmethod
¶
Create a CKAN Package from Data Package
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package |
Package
|
Data Package |
required |
Returns:
Type | Description |
---|---|
CkanPackage
|
CKAN Package |
Source code in dplib/plugins/ckan/models/package.py
to_dp()
¶
Convert to Data Package
Returns:
Type | Description |
---|---|
Package
|
Data Package |
Source code in dplib/plugins/ckan/models/package.py
dplib.plugins.ckan.models.CkanResource
¶
Bases: Model
CKAN Resource model
Source code in dplib/plugins/ckan/models/resource.py
created: Optional[str] = None
class-attribute
instance-attribute
¶
description: Optional[str] = None
class-attribute
instance-attribute
¶
format: Optional[str] = None
class-attribute
instance-attribute
¶
hash: Optional[str] = None
class-attribute
instance-attribute
¶
id: Optional[str] = None
class-attribute
instance-attribute
¶
last_modified: Optional[str] = None
class-attribute
instance-attribute
¶
metadata_modified: Optional[str] = None
class-attribute
instance-attribute
¶
mimetype: Optional[str] = None
class-attribute
instance-attribute
¶
name: str
instance-attribute
¶
size: Optional[int] = None
class-attribute
instance-attribute
¶
url: str
instance-attribute
¶
from_dp(resource)
classmethod
¶
Create CKAN Resource from Data Resource
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource |
Resource
|
Data Resource |
required |
Returns:
Type | Description |
---|---|
Optional[CkanResource]
|
CKAN Resource |
Source code in dplib/plugins/ckan/models/resource.py
to_dp()
¶
Convert to Data Package resource
Returns:
Type | Description |
---|---|
Resource
|
Data Resource |