Welcome to swift-helper’s documentation!
swift_helper
is a small python library written on top of the
swiftclient
library to interact with the OpenStack swift cloud
storage system. With help of this library you can easily list
, remove
,
upload
and download
object on the swift cloud store.
Installation
The library can be installed via pip
python -m pip install swift-helper --extra-index-url gitlab.dkrz.de/api/v4/projects/139460/packages/pypi/simple
Quick Guide
Using the library is relatively straight forward. First you will have to create a swfit session using your login credentials and the so called swift account. The swift account is the data project group this account is associated with.
Note
For private accounts you can set your username as account.
from swift_helper import Swfit
sw = Swift("account", "username")
connection.upload("~/path_to_upload", "name_of_desired_swift_container")
A detailed documentation can be found below:
API Reference
Interact with the content of the dkrz cloud storage.
The module lets you logon to the openstack dkrz cloud storage and interact with the content on it.
- class swift_helper.Swift(account: str, username: Optional[str] = None, password: Optional[str] = None, swift_server: str = 'https://swift.dkrz.de', auth_version: float = 1.0)[source]
Bases:
object
Estabilish a connection to a dkrz swift cloud store.
- Parameters
account (str) – Account name that is used as swift login
username (str, optional) – Username to logon if not given (default) set to account name. Which is equivalent to logging on to the personal siwft.
password (str, optional) –
Password used to logon to the swift store. If not given (default) and a password is needed a password prompt will ask for the password.
Note
A password will only be needed if no login authorisation token exists or the token has expired.
swift_server (str, default: swift.dkrz.de) – The url of the server hosting the cloud storage
auth_version (int, default: 1.0) – The auhtentication version used to establish a connection to the swift server.
- auth_token
Swift authentication token.
- Type
str
Example
from swift_upload import Swift connection = Swift("ch1187", "k204230")
- property auth_url: str
Create the swift authentication url.
- delete(container: str, path: str | Path | None = None) dict[str, Any] [source]
Delete swift object store.
- Parameters
container (str) – Name of the swift object conatiner.
path (str) – name of the swift pseudo folder that should be listed.
- Returns
dict
- Return type
Dictionary holding the information on the delet request.
- exists(container: str, path: Optional[str | Path] = None) bool [source]
Check if container exists and path exists.
- Parameters
container (str) – Name of the swift object container
path (str | Path, default: None) – Pseudo folder in the container
- Returns
bool
- Return type
True if conater and pseudo folder exists.
- property fsspec_auth: list[dict[str, str]]
Get the authentication for swift fsspec.
- static get_passwd(msg: str = 'User password for cloud storage', wait_sec: int = 60) str [source]
Get a password from the getpass prompt
- Parameters
msg – user defined message to be displayed when asking for the password.
wait_sec – amount of seconds to wait before terminating the password request.
- Returns
str
- Return type
the password, empty if terminated.
- get_swift_container_url(container: str, path: Optional[str | Path] = None, scheme: str = 'swift') str [source]
Get the url of the swift storage object.
- Parameters
container (str) – Name of the swift object container
path (str | Path, default: None) – Pseudo folder in the container
scheme (str, default: swift) – url scheme
- Returns
str
- Return type
url of the swift object store
- list(container: str, path: str | Path | None = None, dir_only: bool = False) Iterator[tuple[Path, datetime]] [source]
List the content of a swift container.
- Parameters
container (str) – Name of the swift object container.
path (str) – name of the swift pseudo folder that should be listed.
dir_only (bool, default: False) – List only directory objects
- Yields
os.pathlike – path on the swift container
datetime.datetime – datetime object representing the last modification of the path
- make_public(container: str) None [source]
Make a container public.
- Parameters
container (str) – Name of the swift object container.
- stat(container: str) dict[str, str] [source]
Get the statistics of the swift cloud object store.
- Parameters
container (str) – Name of the swift object container.
- Returns
dict
- Return type
Dictionary holding object store information.
- property swift_file: Path
File where the information to the swift connection is stored.
- upload(inp_dir: Union[str, Path], container: str, public: bool = True) str [source]
Upload a folder to a given swift-container.
- Parameters
inp_dir (str, pathlib.Path) – Source input folder that is going to be uploaded
container (str) – Name of the swift container
public (bool, default: True) – Make the new container public
- Returns
str
- Return type
url to the newly created swift storage object.
See also
- Module
swiftclient
Python library to interact with the swift object store
- Module
swiftspec
Python extension for
fsspec