This project implements an ETL (Extract, Transform, Load) pipeline that securely connects to an SFTP server to retrieve MT940 financial statement files, parses and transforms the content into structured data, and loads the result into a Microsoft SQL Server database.
This pipeline automates the processing of MT940 files typically used in financial transaction reporting. It is designed to:
- Retrieve
.txtfiles in MT940 format from a secure SFTP server. - Parse and normalize banking statement and transaction records.
- Enrich with metadata (e.g., filename, modified time).
- Insert the result into a relational SQL Server table.
This is especially useful for compliance reporting, account reconciliation, and financial data aggregation tasks.
All data comes from an SFTP endpoint hosted by the FAB (First Abu Dhabi Bank) or another entity serving MT940 exports. Key details:
- Files reside in the
/outgoingdirectory. - Each file follows the MT940 SWIFT format and is parsed using the
mt-940library. - Timestamp-based filtering is used to avoid reprocessing files.
Access to the server requires valid credentials and whitelisted IPs.
The main process, executed from main.py, includes:
-
External IP Logging:
- Retrieves and logs the machine’s external IP for traceability.
-
Connect to SFTP:
- Establishes an authenticated session using
paramiko.
- Establishes an authenticated session using
-
Read MT940 Files:
- Loads
.txtfiles, reads content, and parses each into statements and transaction rows.
- Loads
-
Parse & Transform:
- MT940 fields are decoded into a normalized dictionary via a custom transformer.
-
Insert into SQL Server:
- Results are inserted into the table defined by
OUTPUT_TABLE. - Previously inserted files are tracked using
mtime(last-modified timestamp).
- Results are inserted into the table defined by
-
Cleanup:
- Successfully processed files are deleted from the server to prevent duplication.
fab-etl-main/
├── client/ # SFTP and MT940 logic
│ ├── engine.py # Fetch, parse, and manage ETL state
│ └── sftp.py # Secure connection handler
├── config/ # Logging and settings loader
├── database/ # SQL Server interface helpers
├── transformer/ # Data transformation utilities
├── main.py # Entrypoint for pipeline
├── .env.sample # Environment config template
├── Dockerfile # Containerization support
Create a .env file based on .env.sample. Key fields:
| Variable | Description |
|---|---|
SFTP_HOST, SFTP_PORT |
SFTP connection info |
SFTP_USER, SFTP_PASSWORD |
SFTP credentials |
OUTPUT_TABLE |
Target SQL Server table name |
INSERTER_MAX_RETRIES |
Max DB insert retries |
MSSQL_* |
SQL Server configuration |
LOG_LEVEL |
Logging verbosity |
Build and run this ETL as a container:
docker build -t fab-etl .
docker run --env-file .env fab-etlInstall Python dependencies with:
pip install -r requirements.txtKey libraries:
mt-940: MT940 parsingpandas: Data wranglingparamiko: SFTP communicationSQLAlchemy,pyodbc: Database accessfast-to-sql: Bulk data loading
Make sure the .env is correctly configured, then run:
python main.pyLogs will indicate:
- Files downloaded
- Records parsed and inserted
- Cleanup and deletion confirmation
This project is licensed under MIT. Use of MT940 files and connection to remote servers must comply with data agreements and IT security standards.