Skip to content

A lightweight Python CLI tool to connect to Oracle databases, run SQL queries from files or inline, and export results to CSV — built using the modern `oracledb` driver (thin mode, no Oracle client needed). Ideal for automation, reporting & data tasks. Ideal for developers, DBAs, analysts, learners

Notifications You must be signed in to change notification settings

crispusomollo/Oracle-CLI-Tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Oracle CLI Tool (Python)

A lightweight command-line tool to connect to an Oracle database, run SQL queries (inline or from file), and export results to CSV — using Python and the oracledb driver.

Python Oracle DB License: MIT Status CI

✅ Features

  • Connects to Oracle DB (thin mode, no Instant Client required)
  • Run SQL from .sql files or inline strings
  • Export query results to CSV
  • Safe, clean, and easy to extend or integrate into scripts and pipelines
  • Test-covered and modular

📦 Requirements

  • Python 3.7+
  • Oracle database (local or remote)
  • Python package: oracledb

🚀 Setup

  1. Clone the repo
git clone https://github.com/crispusomollo/oracle-cli-tool.git
cd oracle-cli-tool
  1. Create virtual environment
python3 -m venv oracledb-env
source oracledb-env/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Edit config.py to match your Oracle DB credentials:
DB_CONFIG = {
    "user": "your_user",
    "password": "your_password",
    "dsn": "your_host:1521/your_service_name"
}

🖥️ Usage

▶️ Run a saved SQL file

python main.py --query sample_query

(Reads sql/sample query.sql)

▶️ Run an inline SQL query

python main.py --sql "SELECT * FROM employees"

💾 Export query to CSV

python main.py --query sample_query --out result.csv

CSV is saved to output/result.csv

🧪 Run Tests

python3 -m unittest discover tests

🐳 Run with Docker

docker pull crispusmomollo/oracle-cli

docker run --rm \
  -v $(pwd)/sql:/app/sql \
  -v $(pwd)/output:/app/output \
  crispusmomollo/oracle-cli --query sample_query

📁 File Structure

oracle-cli-tool/
├── main.py          # CLI entry point
├── db.py            # DB functions
├── config.py        # Connection details
├── sql/             # Folder for saved queries
│   └── sample_query.sql
├── output/          # CSV exports go here
├── requirements.txt
└── README.md

🧠 Tips

  • Place your queries inside sql/ as .sql files.
  • Refer to them by name (without .sql) using --query.
  • All CSVs are exported to the output/ folder.

📦 Install Notes

Install dependencies manually if needed:

pip install oracledb

🤝 License

MIT — free to use and modify.

📦 Coming Soon

  • Docker support

  • Insert from CSV

  • JSON output

  • GitHub Actions CI

🙌 Contributing

Pull requests and issues welcome! Feel free to fork and enhance.

About

A lightweight Python CLI tool to connect to Oracle databases, run SQL queries from files or inline, and export results to CSV — built using the modern `oracledb` driver (thin mode, no Oracle client needed). Ideal for automation, reporting & data tasks. Ideal for developers, DBAs, analysts, learners

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages