Exporting Oracle Database Using Python

In this post i will show you how to export an Oracle database using a Python script, before using the script ensure that you can made a connection to the database using sqlplus and ensure also that expdp utility is installed.

And you can run it like this :

Ensure that the user you are using to do this export have the permissions to do so, in our example :

That’s it.

  • Suresh

    Thanks for the post. After following all the mentioned steps, I am getting issue as below

    UDE-12560: operation generated ORACLE error 12560
    ORA-12560: TNS:protocol adapter error

    FYR, constructed expdp_args string is “generaldb/generaldb123@ORCL SCHEMAS=GENERALDB DIRECTORY=DBBACKUP DUMPFILE=GENERALDB_DUMP_PY_230320201800.dmp LOGFILE=expdb_py.log”

    and db_env is {

    ‘PATH’: ‘C:\Oracle\WINDOWS.X64_193000_db_home\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk1.8.0_241\bin;C:\Users\sureshd\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\sureshd\AppData\Local\Programs\Python\Python37\;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\sureshd\AppData\Local\Microsoft\WindowsApps;C:\Users\sureshd\AppData\Roaming\npm;C:\Users\sureshd\AppData\Local\Programs\Microsoft VS Code\bin’,

    ‘ORACLE_HOME’: ‘C:\Oracle\WINDOWS.X64_193000_db_home’,

    ‘TNS_ADMIN’: ‘C:\Oracle\WINDOWS.X64_193000_db_home\network\admin’,

    ‘LD_LIBRARY_PATH’: ‘C:\Oracle\WINDOWS.X64_193000_db_home\lib’
    }

    But above constructed expdp_args string is working fine through command line. It is successfully creating the dump file. The issue is only coming through Python code.

    Listeners and services are running. I am able to do tnsping successfully.

    Could you please guide me what I am doing wrong here.