isogeo_pysdk.api.routes_link module
Isogeo API v1 - API Routes to manage metadata links.
See: http://help.isogeo.com/api/complete/index.html
- class isogeo_pysdk.api.routes_link.ApiLink(api_client=None)
Bases:
object
Routes as methods of Isogeo API used to manipulate metadata links (CGUs).
- clean_kind_action_liability(link_actions, link_kind)
Link available actions depend on link kind. Relationships between kinds and actions are described in the /link-kinds route. This is a helper checking the liability between kind/actions/type and cleaning if needed. Useful before creating or updating a link.
# invalid action will be removed print(isogeo.metadata.links.clean_kind_action_liability( link_actions=("download", "stream"), link_kind="url" ) ) >>> ('download',)
- create(metadata, link, clean_actions=True)
Add a new link to a metadata (= resource).
- Parameters
- Returns
the created link or a tuple with the request’s response error code
- Return type
- Example
# retrieve metadata md = isogeo.metadata.get(METADATA_UUID) # create the link locally new_link = Link( type="url", restriction="patent", description="Do not use for commercial purpose.", ) # add it to the metadata isogeo.metadata.links.create(md, new_link) # to create a link which is a pointer to another link, add the link attribute: new_link = Link( actions=["other"], title="Associated link", kind="url", type="link", link=Link(_id=LINK_UUID) )
- delete(link, metadata=None)
Delete a link from a metadata.
- download_hosted(link, encode_clean=1)
Download hosted resource.
- Parameters
- Returns
tuple(stream, filename, human readable size)
- Return type
Example:
# get links from a metadata md_links = isogeo.metadata.links.listing(Metadata(_id=METADATA_UUID)) # filter on hosted links hosted_links = [ link for link in md_links if link.get("type") == "hosted" ] # get the stream, the filename and the size (in human readable format) dl_stream = isogeo.metadata.links.download_hosted(Link(**hosted_links[0])) # download the file and store it locally with open("./" + dl_stream[1], "wb") as fd: for block in dl_stream[0].iter_content(1024): fd.write(block)
- get(metadata_id, link_id)
Get details about a specific link.
# get a metadata md = isogeo.metadata.get(METADATA_UUID) # list its links md_links = isogeo.metadata.links.listing(md) # get the first link link = isogeo.metadata.links.get( metadata_id=md._id, link_id=md_links[0].get("_id") )
- kinds_actions(caching=1)
Get the relation between kinds and action for links.
- Parameters
caching (bool) – cache the response into the main API client instance. Defaults to True.
- Returns
list of dictionaries per link kinds
- Return type
- Example
import pprint pprint.pprint(isogeo.metadata.links.kinds_actions()) >>> [ { 'actions': [ 'download', 'view', 'other' ], 'kind': 'url', 'name': 'Lien' }, { 'actions': ['download', 'view', 'other'], 'kind': 'wfs', 'name': 'Service WFS' }, { 'actions': ['view', 'other'], 'kind': 'wms', 'name': 'Service WMS' }, { 'actions': ['view', 'other'], 'kind': 'wmts', 'name': 'Service WMTS' }, { 'actions': ['download', 'view', 'other'], 'kind': 'esriFeatureService', 'name': 'Service ESRI Feature' }, { 'actions': ['view', 'other'], 'kind': 'esriMapService', 'name': 'Service ESRI Map' }, { 'actions': ['view', 'other'], 'kind': 'esriTileService', 'name': 'Service ESRI Tile' }, { 'actions': ['download', 'other'], 'kind': 'data', 'name': 'Donnée brute' } ]
- listing(metadata)
Get links of a metadata.
- update(link, metadata=None)
Update a link.
- upload_hosted(metadata, link, file_to_upload)
Add a new link to a metadata uploading a file to hosted data. See: https://requests.readthedocs.io/en/latest/user/quickstart/#post-a-multipart-encoded-file
- Parameters
- Returns
the new Link if successed or the tuple with the request error code
- Return type
- Example
from pathlib import Path # define metadata md = isogeo.metadata.get(METADATA_UUID) # localize the file on the OS my_file = Path("./upload/documentation.zip") # create the link locally lk = Link( title=my_file.name ) # add it to the metadata send = isogeo.metadata.links.upload_hosted( metadata=md, link=lk, file_to_upload=my_file.resolve() )