Skip to main content

iLibrary

A lightweight Python helper for working with IBM i (AS/400) libraries. It connects via ODBC (pyodbc) for DB2/SQL queries and uses Paramiko for SSH/SFTP to save and transfer library save files (SAVF).

PyPI Downloads

Overview

  • Query library metadata using QSYS2 services
  • List objects in a library (and optionally source physical files)
  • Create a save file (SAVF) for a library via SAVLIB and optionally download it
  • Remove save files
  • Simple context manager to handle DB connection lifecycle

Requirements

  • Python 3.8+
  • IBM i system access
  • IBM i Access ODBC Driver (or compatible) installed locally
  • Network access to the IBM i for ODBC and SSH/SFTP

Installation

  • From PyPI: pip install iLibrary
  • From source:
    • Clone the repo
    • Optionally create and activate a virtual environment
    • pip install -r requirements.txt
    • pip install -e .

Quickstart

import json
from os.path import join
import os
from dotenv import load_dotenv
from iLibrary import Library

#load ENV file and get the Connection Settings
dotenv_path = join('.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")




# ----------------------------------------------------
# make a Savefile from a library
# ----------------------------------------------------
def getSaveFile():

    # Flag to enable/disable Mapepire connection mode
    USE_MAPEPIRE = False


    PORT = 22 #for the Pub400.com use the Port 2222
    LIBRARY = '<LIBRARY_TO_SAVE>'
    SAVE_FILE_NAME = 'FOO'
    LOCAL_PATH = 'YOUR_LOCAL_PATH'
    DESCRIPTION = 'Saved from iLibrary'
    try:
        # Establish a connection to the IBM i system using the User class
        # The context manager ensures the connection is properly opened and closed
        with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER, mapepire=USE_MAPEPIRE) as l:

            # Call the method to save the Library
            # The result is returned as a JSON string
            raw_result = l.saveLibrary(
                library=LIBRARY,
                saveFileName=SAVE_FILE_NAME,
                description=DESCRIPTION,
                localPath=LOCAL_PATH,
                port=PORT
            )

            # Parse the JSON string into a Python object (list/dictionary)
            data = json.loads(raw_result)

            # Pretty-print the parsed data with indentation for readability
            print(json.dumps(data, indent=4))

    # Handle any exceptions that occur during connection or data retrieval
    except Exception as e:
        # Print the error message for debugging
        print(e)



# ----------------------------------------------------
# Get library information about all libraries from
# IBM i Server using iLibrary
# ----------------------------------------------------
def getAllLibraries():
    # Flag to enable/disable Mapepire connection mode
    USE_MAPEPIRE = False

    try:
        # Establish a connection to the IBM i system using the User class
        # The context manager ensures the connection is properly opened and closed
        with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER, mapepire=USE_MAPEPIRE) as l:

            # Call the method to get all libraries on the system
            # The result is returned as a JSON string
            raw_result = l.getAllLibraries()

            # Parse the JSON string into a Python object (list/dictionary)
            data = json.loads(raw_result)

            # Pretty-print the parsed data with indentation for readability
            print(json.dumps(data, indent=4))

    # Handle any exceptions that occur during connection or data retrieval
    except Exception as e:
        # Print the error message for debugging
        print(e)




# ----------------------------------------------------
# Get single library information from IBM i Server
# using iLibrary
# ----------------------------------------------------
def getSingleLibraryInfo():
    # Flag to enable/disable Mapepire connection mode
    USE_MAPEPIRE = False
    LIBRARY = '<LIBRARY>'
    try:
        # Establish a connection to the IBM i system using the User class
        # The context manager ensures the connection is properly opened and closed
        with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER, mapepire=USE_MAPEPIRE) as l:

            # Call the method to show singe information about the Library
            # The result is returned as a JSON string
            raw_result = l.getLibraryInfo(
                library=LIBRARY
            )

            # Parse the JSON string into a Python object (list/dictionary)
            data = json.loads(raw_result)

            # Pretty-print the parsed data with indentation for readability
            print(json.dumps(data, indent=4))

    # Handle any exceptions that occur during connection or data retrieval
    except Exception as e:
        # Print the error message for debugging
        print(e)

if __name__ == '__main__':
    getSaveFile()
    getAllLibraries()
    getSingleLibraryInfo()

More Examples:

Configuration

  • Environment variables expected:
    • DB_DRIVER: e.g. {IBM i Access ODBC Driver}
    • DB_USER
    • DB_PASSWORD
    • DB_SYSTEM

Contributing

  • Please run tests or the sample script before submitting changes.

License

  • See the repository license file if present.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ilibrary-0.0.17.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ilibrary-0.0.17-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file ilibrary-0.0.17.tar.gz.

File metadata

  • Download URL: ilibrary-0.0.17.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ilibrary-0.0.17.tar.gz
Algorithm Hash digest
SHA256 4faff2f71db45dcc0e08cba65c45c0fd9b8d5bf53ad30f2f76c5d7464590882e
MD5 69ff47abd06b6670682860168ac87d78
BLAKE2b-256 ed515af23fd0294ce599a644ea8e9664b4cc0bcc4abe66ea3f113ec542eb67d6

See more details on using hashes here.

File details

Details for the file ilibrary-0.0.17-py3-none-any.whl.

File metadata

  • Download URL: ilibrary-0.0.17-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ilibrary-0.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 4d14f11474ffc68d1be844d5d9854dbca123af90b1a3906c869f102236c15b5c
MD5 78015d3b5731d3abd7088db8639dfbe6
BLAKE2b-256 34fbb523bfed3fd6279b3dfd32896a9a9424f5368a72ce2d35f371eebfd0559d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.17 This release

2 files

0.0.16

2 files

0.0.15

2 files

0.0.14

1 file

0.0.13

1 file

0.0.12

1 file

0.0.11

1 file

0.0.10

1 file

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page