This modern, type-annotated Python library streamlines ODBC connectivity to IBM iSeries (AS/400) servers. Built on top of pyODBC, it offers a clean, Pythonic interface for seamless interaction with iSeries systems.
On Windows, this library eliminates the need to manually configure user or system DSNs in the ODBC Administrator, allowing direct connections with simple Python code.
- π Secure Connection Management: Context manager support with automatic cleanup
- π Type Hints: Full type annotation support for better IDE experience
- π‘οΈ Error Handling: Comprehensive exception handling with detailed logging
- π§ CL Command Support: Execute iSeries CL commands directly from Python
- π Query Interface: Simple, generator-based query execution
- π File Operations: Built-in support for common iSeries file operations (DSPFD, DSPFFD, etc.)
- π FTP Integration: Upload files to iSeries via FTP
- π Well Documented: Comprehensive docstrings and examples
pip install iseries- Python 3.7+
- pyodbc 4.0+
- iSeries Access ODBC Driver
from iseries import Connect
# Using context manager (recommended)
with Connect(host='your-iseries', user='username',
pwd='password', lib='MYLIB') as conn:
# Execute a query
results = conn.query("SELECT * FROM MYTABLE")
for row in results:
print(row)from iseries import Connect
conn = Connect(host='your-iseries', user='username',
pwd='password', lib='MYLIB')
try:
results = conn.query("SELECT COUNT(*) FROM MYTABLE")
count = next(results)[0]
print(f"Table has {count} rows")
finally:
conn.close()with Connect(host='your-iseries', user='username',
pwd='password', lib='MYLIB') as conn:
# Display file field description
results = conn.dspffd('MYLIB', 'OUTFILE', 'MYTABLE')
for row in results:
print(row)with Connect(host='your-iseries', user='username',
pwd='password', lib='MYLIB') as conn:
conn.ftpSend('/path/to/local/file.txt', 'TARGETLIB')# Use SQL naming convention (default is DB2)
with Connect(host='your-iseries', user='username',
pwd='password', lib='MYLIB', naming=0) as conn:
results = conn.query("SELECT * FROM MYLIB.MYTABLE")with Connect(host='your-iseries', user='username',
pwd='password', lib='MYLIB') as conn:
results = conn.query("SELECT * FROM MYTABLE WHERE ID = ?", 123)
for row in results:
print(row)from iseries import rand_filename, today, now
# Generate random filename
filename = rand_filename(8) # e.g., 'ABCD1234'
# Get current date as integer (YYYYMMDD)
current_date = today() # e.g., 20231215
# Get current time as integer (HHMMSS)
current_time = now() # e.g., 143025The library provides comprehensive error handling:
import pyodbc
from iseries import Connect
try:
with Connect(host='invalid-host', user='user',
pwd='pwd', lib='LIB') as conn:
results = conn.query("SELECT * FROM NONEXISTENT")
except pyodbc.Error as e:
print(f"Database error: {e}")
except ValueError as e:
print(f"Configuration error: {e}")
except FileNotFoundError as e:
print(f"File operation error: {e}")Connect(host, user, pwd, lib, naming=1, autocommit=False)Parameters:
host(str): iSeries hostname or IP addressuser(str): Username for authenticationpwd(str): Password for authenticationlib(str): Default librarynaming(int): Naming convention (0=SQL, 1=DB2, default=1)autocommit(bool): Enable autocommit mode (default=False)
query(statement, *parameters): Execute SQL queryexecuteCLCmd(cmd, output=None): Execute CL commanddspfd(library, output, file_name='*ALL', ...): Display file descriptiondspffd(library, output, file_name='*ALL'): Display file field descriptiondspobjd(library, object, object_type, output, ...): Display object descriptioncpyf(from_table, from_lib, to_table, to_lib, mbropt, crtfile): Copy filechgdtaara(data_area, library, value): Change data areaftpSend(file_path, library): Upload file via FTPclose(): Close connection
- Using environment variables for credentials
- Implementing credential management systems
- Using encrypted configuration files
- Regular credential rotation
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Added comprehensive type hints
- Improved error handling and logging
- Enhanced documentation
- Better security practices
- Updated package metadata
- Initial release