Welcome to Pacifica Python Downloader’s documentation!¶
The Pacifica Python Downloader library provides a Python API for downloading data from the Pacifica Core services. The Python Downloader allows users to build custom applications to download data from Pacifica.
Installation¶
The Pacifica software is available through PyPi so creating a virtual environment to install is what is shown below. Please keep in mind compatibility with the Pacifica Core services.
Installation in Virtual Environment¶
These installation instructions are intended to work on both Windows, Linux, and Mac platforms. Please keep that in mind when following the instructions.
Please install the appropriate tested version of Python for maximum chance of success.
Linux and Mac Installation¶
mkdir ~/.virtualenvs
python -m virtualenv ~/.virtualenvs/pacifica
. ~/.virtualenvs/pacifica/bin/activate
pip install pacifica-downloader
Windows Installation¶
This is done using PowerShell. Please do not use Batch Command.
mkdir "$Env:LOCALAPPDATA\virtualenvs"
python.exe -m virtualenv "$Env:LOCALAPPDATA\virtualenvs\pacifica"
& "$Env:LOCALAPPDATA\virtualenvs\pacifica\Scripts\activate.ps1"
pip install pacifica-downloader
Code Examples¶
The Python Downloader has two architectural pieces. The first are a set of methods to manipulate metadata about files and generate a Cartd friendly metadata document. The second is a set of methods to interact with the Cartd service to wait and download the files.
Download Transaction Info¶
The download setup described below creates a temporary directory to download the data to.
from tempfile import mkdtemp
down_path = mkdtemp()
down = Downloader(down_path, 'http://127.0.0.1:8081')
resp = requests.get('http://127.0.0.1:8181/status/transactions/by_id/67')
assert resp.status_code == 200
down.transactioninfo(resp.json())
Download Cloud Event¶
Often CloudEvents are handled in web server frameworks. Here’s an example of using the downloader in CherryPy. This example can be launched as a consumer of CloudEvents sent by the Pacifica Notifications service.
from tempfile import mkdtemp
import cherrypy
class Root(object):
exposed = True
@cherrypy.tools.json_in()
@cherrypy.tools.json_out()
def POST(self):
"""Accept the cloud event data and return the local download path."""
down_path = mkdtemp()
down = Downloader(down_path, 'http://127.0.0.1:8081')
down.cloudevent(cherrpy.request.json)
return { 'download_path': down_path }
cherrypy.quickstart(Root(), '/', {
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher()
}
})
Downloader Python Module¶
Downloader Python Module¶
The Downloader internal Module.
-
class
pacifica.downloader.downloader.
Downloader
(location, cart_api_url, **kwargs)[source]¶ Downloader Class.
The constructor takes two arguments location and cart_api_url. The location is a download directory to be created by a download method. The cart_api_url is the endpoint for creating carts.
The other methods in this class are the supported download methods. Each method takes appropriate input for that method and the method will download the data to the location defined in the constructor.
-
__weakref__
¶ list of weak references to the object (if defined)
-
_download_from_url
(cart_url, filename)[source]¶ Download the cart from the url.
The cart url is returned from the CartAPI.
-
cloudevent
(cloudevent, filename='data')[source]¶ Handle a cloud event and download the data in a cart.
CloudEvents is a specification for passing information about changes in cloud infrastructure or state. This method consumes events produced by the Pacifica Notifications service.
-
CartAPI Python Module¶
Cart API module for interacting with carts.
-
class
pacifica.downloader.cartapi.
CartAPI
(cart_api_url, **kwargs)[source]¶ Cart api object for manipulating carts.
This class has two methods used for setting up a cart and waiting for completion.
-
__init__
(cart_api_url, **kwargs)[source]¶ Constructor for cart api.
The constructor takes a required URL to the Cart API. Optionally, there can be passed a requests session via keyword arguments. Also, an optional requests authentication dictionary can be passed via keyword arguments.
-
__weakref__
¶ list of weak references to the object (if defined)
-
CloudEvent Python Module¶
Cloud Event Parser.
Pacifica Downloader Module.
The primary exposed class is the Downloader class. There are two internal classes to pull the metadata required to interact with the Cartd service.
-
class
pacifica.downloader.
Downloader
(location, cart_api_url, **kwargs)[source]¶ Downloader Class.
The constructor takes two arguments location and cart_api_url. The location is a download directory to be created by a download method. The cart_api_url is the endpoint for creating carts.
The other methods in this class are the supported download methods. Each method takes appropriate input for that method and the method will download the data to the location defined in the constructor.
-
__weakref__
¶ list of weak references to the object (if defined)
-
_download_from_url
(cart_url, filename)[source]¶ Download the cart from the url.
The cart url is returned from the CartAPI.
-
cloudevent
(cloudevent, filename='data')[source]¶ Handle a cloud event and download the data in a cart.
CloudEvents is a specification for passing information about changes in cloud infrastructure or state. This method consumes events produced by the Pacifica Notifications service.
-