iLibrary - Tools for IBM i
Project description
iLibrary
This class provides methods to connect to the system via pyodbc for SQL and paramiko for SFTP transfers.
Modules required
- json
- os
- paramiko
- pyodbc
Class Library
A class to manage libraries and files on an IBM i system. It provides methods to connect to the system via pyodbc for SQL and paramiko for SFTP transfers.
Methods
enter(self) -> 'Library'
Establishes the database connection when entering a with block.
exit(self, exc_type, exc_val, exc_tb)
Closes the database connection when exiting a with block. This method is called automatically, even if an error occurred.
init(self, db_user: str, db_password: str, db_host: str, db_driver: str)
Initializes the class attributes for a database connection. The actual connection is established in the __enter__ method.
-
Args:
db_user(str): The user ID for the database connection.db_password(str): The password for the database user.db_host(str): The system/host name for the database connection.db_driver(str): The ODBC driver to be used.
getInfoForLibrary()
Retrieves information about a specific library.
Args:
-
library(str): The name of the library to retrieve information about. -
wantJson(bool, optional): If set toTrue, the function returns a JSON-formatted string. IfFalse, it returns a Python object. Defaults toTrue.
Returns: -
str: A JSON string ifwantJsonis True. -
obj: A Python object ifwantJsonis False.
Example:
from os.path import join, dirname
import os
from dotenv import load_dotenv
import iLibrary
#load ENV file and get the Connection Settings
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
DB_DRIVER = os.environ.get("DB_DRIVER")
DB_USER = os.environ.get("DB_USER")
DB_PASSWORD = os.environ.get("DB_PASSWORD")
DB_SYSTEM = os.environ.get("DB_SYSTEM")
if __name__ == "__main__":
try:
with iLibrary.Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER) as lib:
#try to get the SAVF File from the IBM i Server
result = lib.getInfoForLibrary('LIB_NAME')
print(f"Query result: {result}")
except Exception as e:
print(f"An error occurred in the main block: {e}")
iclose(self)
A helper method to close the connection, also useful for manual closure.
saveLibrary()
Saves a complete library from the IBM i to a save file.
This method creates a save file on the IBM i and then uses the SAVLIB (Save Library) CL command to save the specified library's contents into it. Optionally, it can download the resulting save file to the local machine as a ZIP file.
Args:
-
library(str): The name of the library to be saved. -
saveFileName(str): The name of the save file that will be created to hold the library. -
description(str, optional): A text description for the save file. Defaults to None. -
localPath(str, optional): The local file path where the downloaded save file will be stored. Required ifgetZipis True. Defaults to None. -
remPath(str, optional): The remote file path on the IBM i's IFS where the save file will be temporarily stored before downloading. Required ifgetZipis True. Defaults to None. -
getZip(bool, optional): If True, the save file will be downloaded to the local machine and then deleted from the remote IFS. Defaults to False. -
port(int, optional): The port for the SSH connection. Defaults to 22.
Returns:
bool:Trueif the library was saved successfully (and downloaded if requested),Falseotherwise.
Example
from os.path import join, dirname
import os
from dotenv import load_dotenv
import iLibrary
#load ENV file and get the Connection Settings
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
DB_DRIVER = os.environ.get("DB_DRIVER")
DB_USER = os.environ.get("DB_USER")
DB_PASSWORD = os.environ.get("DB_PASSWORD")
DB_SYSTEM = os.environ.get("DB_SYSTEM")
if __name__ == "__main__":
try:
with iLibrary.Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER) as lib:
#try to get the SAVF File from the IBM i Server
result = lib.saveLibrary(library='YOUR_LIB', saveFileName='SAVEFILE_NAME', getZip=True, localPath=join(dirname(__file__)), remPath='/home/USERNAME/')
print(f"Query result: {result}")
except Exception as e:
print(f"An error occurred in the main block: {e}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ilibrary-0.0.3.tar.gz.
File metadata
- Download URL: ilibrary-0.0.3.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5019a99cc6db559b8dd1a7e3b9e062758b7bd98f8a673cac961040f6a20ad1b
|
|
| MD5 |
d3c530e39391c705bf5e35b2aaef9118
|
|
| BLAKE2b-256 |
6d77a965dceb6f2df2a65af698233db16d35c9509fe619841069fc5a4769808b
|
File details
Details for the file ilibrary-0.0.3-py3-none-any.whl.
File metadata
- Download URL: ilibrary-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bedd815e08096b6ccecfc5f0758f01acc25d97babf4414963f7f5385e284f658
|
|
| MD5 |
69c604d671e3082a2bbc2228aa9382d7
|
|
| BLAKE2b-256 |
fb0ca7b857b848d55d58b6e96c214d96228ac6216fa5eac49c02c1b3a95691b4
|