{"id":18802179,"url":"https://github.com/oracle-quickstart/webapp-python-oracledb-flask-api","last_synced_at":"2026-03-16T21:04:25.630Z","repository":{"id":185776661,"uuid":"613432111","full_name":"oracle-quickstart/webapp-python-oracledb-flask-api","owner":"oracle-quickstart","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-18T07:02:40.000Z","size":56,"stargazers_count":5,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-18T07:25:18.664Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oracle-quickstart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-13T14:59:32.000Z","updated_at":"2025-02-18T07:02:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"54eb6cb0-04e6-4b1d-9690-c278223af37c","html_url":"https://github.com/oracle-quickstart/webapp-python-oracledb-flask-api","commit_stats":null,"previous_names":["oracle-quickstart/webapp-python-oracledb-flask-api"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oracle-quickstart%2Fwebapp-python-oracledb-flask-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oracle-quickstart%2Fwebapp-python-oracledb-flask-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oracle-quickstart%2Fwebapp-python-oracledb-flask-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oracle-quickstart%2Fwebapp-python-oracledb-flask-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oracle-quickstart","download_url":"https://codeload.github.com/oracle-quickstart/webapp-python-oracledb-flask-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239735263,"owners_count":19688262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T22:26:53.704Z","updated_at":"2026-03-16T21:04:25.617Z","avatar_url":"https://github.com/oracle-quickstart.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EMS Demo App - RESTful APIs on Oracle Database with Python Flask \nA Demo App build with Python3, Flask Package and Oracle Autonomous Database\n\nThe python-flask-demo-oracle repository contains a simple Flask application that demonstrates how to connect to an Oracle Autonomous database (or any other Oracle Database) and perform basic CRUD (Create, Read, Update, Delete) operations on a database table.\n\nThe application consists of a single Flask app defined in the main.py file, which serves as the entry point for the application. The main.py file defines several Flask routes (i.e. URL endpoints) that handle HTTP requests from clients and return HTTP responses.\n\nThe main features of the application are:\n\n   1. Database connection: The app connects to an Oracle database using the python-oracldb library and a DSN (Data Source Name) string that specifies the hostname, port, service name, username, and password for the database connection.\n\n   2. CRUD operations: The app allows users to perform basic CRUD operations on a database table called employees. Users can add new employees, view all employees, update employee information, and delete employees.\n\n  3.  SSL/TLS encryption: The app uses SSL/TLS encryption to secure HTTP traffic between the client and server. You can use self-signed SSL certificates, and the Flask app is configured to use this certificate to encrypt HTTP traffic.\n\nThe repository also contains several HTML templates that define the app's user interface. The base.html template defines the basic layout of the app, while the other templates extend this base template and define the content for specific pages (e.g. the add employee form, the view employees page, etc.).\n\n\n## Quick Build \u0026 Deploy with Docker or Podman\n#### 1. Clone the Repo\n\n```\ngit clone https://github.com/oracle-quickstart/webapp-python-oracledb-flask-api.git \u0026\u0026 cd webapp-python-oracledb-flask-api/\n\n```\n\n#### 2. Generate the self-signed certificates\n\n```\nopenssl genrsa -out key.pem 2048\n\nopenssl req -new -x509 -newkey rsa:2048 -key key.pem -out cert.pem\n\nchmod +r cert.pem key.pem\n```\n  \n#### 3. Check for certificate and key file\n\n```\nls -ltr\n```\n\n#### 4. Replace username,password \u0026 connection string in main.py with your Autonomous DB details\n```\nvim main.py\n```\n\n#### 5. Create table in Autonomous DB\n\n```\nCREATE TABLE employees (\n    id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,\n    name VARCHAR2(255) NOT NULL,\n    email VARCHAR2(255) NOT NULL,\n    department VARCHAR2(255) NOT NULL\n);\n```\n\n#### 6. Enable port 4443 on local machine where you are running Docker (Linux only)\n```\nsudo firewall-cmd --permanent --add-port=4443/tcp\nsudo firewall-cmd --reload\nsudo firewall-cmd --zone=public --permanent --list-ports\n```\n\n#### 7. Build the Docker Image\n\n```\n docker build -t oracleflaskdemo .\n```\n\n#### 8. Run the Docker Container\n\n```\ndocker run -p 4443:4443 \\\n-e ORACLE_USER=admin \\\n-e ORACLE_PASSWORD=YourP@ssword1234#_ \\\n-e ORACLE_DSN=\"(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.ap-melbourne-1.oraclecloud.com))(connect_data=(service_name=******_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)))\" oracleflaskdemo\n```\n\n#### Note : If you are using Podman instead of Docker, just replaced 'docker' with 'podman' in the commands\n```\n# Install Podman on MacOS M1 Pro\nbrew install podman\npodman machine init\npodman machine set -m 3072\npodman machine start\n\n# Build Flask App\npodman build -t oracleflaskdemo .\n\npodman run -p 4443:4443 \\\n-e ORACLE_USER=admin \\\n-e ORACLE_PASSWORD=YourP@ssword1234#_ \\\n-e ORACLE_DSN=\"(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.ap-melbourne-1.oraclecloud.com))(connect_data=(service_name=******_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)))\" oracleflaskdemo\n```\n\n# App Testing \n\n## Main Page \n#### Open in browser\n\n```\nhttps://127.0.0.1:4443/api/main\n```\n\n#### Enter API Username \u0026 Password\n```\nUsername : user1\nPassword : password1\n```\n\n\u003cimg width=\"428\" alt=\"Screen Shot 2023-03-11 at 11 22 25 pm\" src=\"https://user-images.githubusercontent.com/39692236/224484216-72b14f5c-6607-4d23-8d85-8992984956bd.png\"\u003e\n\n\u003cimg width=\"1439\" alt=\"Screen Shot 2023-03-11 at 11 20 40 pm\" src=\"https://user-images.githubusercontent.com/39692236/224484111-2986bfd0-a731-4d51-8649-fabf96fa5bd1.png\"\u003e\n\n## Create Employee\n#### Open in browser\n\n```\nhttps://127.0.0.1:4443/api/add_employee\n```\n\n\u003cimg width=\"1623\" alt=\"Screen Shot 2023-03-12 at 10 54 57 am\" src=\"https://user-images.githubusercontent.com/39692236/224516956-bbbfdfbb-9361-434d-9646-8064c1acc14a.png\"\u003e\n\n## READ Employees\n\n#### Open in browser\n\n```\nhttps://127.0.0.1:4443/api/getall\n```\n\n\n\u003cimg width=\"1756\" alt=\"Screen Shot 2023-03-12 at 10 55 11 am\" src=\"https://user-images.githubusercontent.com/39692236/224516971-bac05ac8-7e85-4be5-b7e2-d76cdfcdacd1.png\"\u003e\n\n\n## UPDATE Employee\n\n#### Open in browser\n\n```\nhttps://127.0.0.1:4443/api/update_employee/101\n```\n\n\u003cimg width=\"1545\" alt=\"Screen Shot 2023-03-12 at 11 07 25 am\" src=\"https://user-images.githubusercontent.com/39692236/224517115-08a16e38-4a16-4856-8d08-b2725b5d202f.png\"\u003e\n\n\n\u003cimg width=\"1709\" alt=\"Screen Shot 2023-03-12 at 11 10 52 am\" src=\"https://user-images.githubusercontent.com/39692236/224517167-9d1a16a8-f040-4a12-9e93-ae96ef5e482b.png\"\u003e\n\n\n## DELETE Employee\n\n#### Open in browser\n\n```\nhttps://127.0.0.1:4443/api/delete_employee/101\n```\n\n\u003cimg width=\"886\" alt=\"Screen Shot 2023-03-12 at 11 11 33 am\" src=\"https://user-images.githubusercontent.com/39692236/224517187-ca26fed8-de20-4f75-9507-83a7ae453806.png\"\u003e\n\n\n\n\n## Oracle Linux VM Deploy \n\n### 1. Install Python, flask , cx_Oracle, Jinga2 \u0026 six packages on Oracle Linux 8\n\nFirst pre-requisite is to ensure your instance has Python3 installed along with the Python packages. We will also install the command-line browser links to test the API using a html form.\n\n```\n  sudo yum install links gcc openssl-devel libffi-devel bzip2-devel wget openssl\n\n  sudo pip3 install flask\n  sudo pip3 install flask_cors\n  sudo pip3 install six\n  sudo pip3 install Jinja2\n  sudo pip3 install oracledb\n```\n\n```\n  a. Verify latest version of Python\n  Verify the latest version of Python at https://www.python.org/ftp/python/\n  In this case the version to be installed is 3.8.9. \n\n  b. Download the tar file\n  $ cd /tmp\n  $ wget https://www.python.org/ftp/python/3.8.9/Python-3.8.9.tgz\n  $ tar xzvf Python-3.8.9.tgz -C /opt\n\n  c. Compile and install\n  $ cd Python-3.8.9/\n  $ sudo ./configure --enable-optimizations\n  $ sudo make altinstall\n\n  d. Verify the installation\n  python3.8 --version or python3.8 -V\n\n```\n\n### 2. Generate Self-signed certificates and firewall rules\n\nAs we are creating a secure web server ensure you need SSL certificates. In this example for demo purposes we are creating self-signed certificates but in a production scenario you should have SSL certificates issued from a third party authority.\n\n```\nopenssl genrsa -out key.pem 2048\n\nopenssl req -new -x509 -newkey rsa:2048 -key key.pem -out cert.pem\n\nchmod +r cert.pem key.pem\n\nsudo firewall-cmd --permanent --add-port=4443/tcp\nsudo firewall-cmd --reload\nsudo firewall-cmd --zone=public --permanent --list-ports\n```\n\n### 3. Deploy the Oracle Table\n\nThe example uses a simple table called employees in the hr schema. An identity column is used to auto-increment the id of the employee\n\n```\nCREATE TABLE employees (\n    id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,\n    name VARCHAR2(255) NOT NULL,\n    email VARCHAR2(255) NOT NULL,\n    department VARCHAR2(255) NOT NULL\n);\n```\n\n### 4. Clone the Repo \u0026 Install Python Packages \n\n```\ngit clone https://github.com/oracle-quickstart/webapp-python-oracledb-flask-api.git\n\ncd webapp-python-oracledb-flask-api/\n\npip3 install -r requirements.txt\n\n```\n\n\n\n### 5. Change path for template_folder in main.py to reflect the local directory where .html files and code is stored :\n\n\n```\napp = Flask(__name__, template_folder='\u003cyour local directory\u003e')\n```\n\nThis will allow two web pages one for the POST request to the “/api/add_employee” endpoint and another for getting a list of all employees in the databases via \"/api/getall\"\n\n### 6. Change path for SSL certificates in main.py file to location of SSL certificates created in Step 2.\n\n```\n    app.run(host='0.0.0.0', port=4443, ssl_context=('cert.pem', 'key.pem'))\n```\n\n### 7. If using mTLS, download and configure the ADB wallet files\n\nIf mTLS is being used to connect to an ADB instance, then perform this step to configure the wallet on the VM. If using TLS or not connecting to a database that requires a wallet to connnect, then skip to step 8. \n\nDownload the ADB wallet files for the target ADB and unzip in a directory on the VM, and modify the sqlnet.ora within the wallet files to reflect the correct TNS_ADMIN directory. \n\n```\nWALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY=\"/local/directory/wallet\")))\n```\n\nUpdate main.py by uncommenting the lines for **wallet_location** and **wallet_password.**\n\n```\ndsn = os.environ['ORACLE_DSN']\nwallet_location = os.environ['TNS_ADMIN']               \u003c\u003c\u003c\u003c\u003c\u003c\nwallet_password = os.environ['ORACLE_WALLET_PWD']         \u003c\u003c\u003c\u003c\u003c\u003c\n\n..\n\n    pool = oracledb.create_pool(user=user,\n                                   password=password,\n                                   dsn=dsn,\n                                   wallet_location=wallet_location,      \u003c\u003c\u003c\u003c\u003c\n                                   wallet_password=wallet_password,      \u003c\u003c\u003c\u003c\u003c\n\n```\n\n\n\n### 7. Run the Python script\n\nSet Oracle Database Environment Variables\n\n```\nexport ORACLE_USER=admin \nexport ORACLE_PASSWORD=YourPass@word1234#_ \nexport ORACLE_DSN=\"(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=adb.ap-melbourne-1.oraclecloud.com))(connect_data=(service_name=*****_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)))\"\n\n-- If using the ADB wallet configured in Step 7, include the following parameters:\nexport TNS_ADMIN=\u003clocation of wallet files\u003e\nexport ORACLE_WALLET_PWD=\u003cpassword of wallet files\u003e\n\n```\n\n```\n$ python3 main.py \n         * Running on https://10.180.1.21:4443/ (Press CTRL+C to quit)\n ```\n\n## Contributing\n\nThis project welcomes contributions from the community. Before submitting a pull request, please [review our contribution guide](./CONTRIBUTING.md)\n\n## Security\n\nPlease consult the [security guide](./SECURITY.md) for our responsible security vulnerability disclosure process\n\n## License\n\nCopyright (c) 2023 Oracle and/or its affiliates.\n\nReleased under the Apache License Version 2.0 as shown at http://www.apache.org/licenses/.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foracle-quickstart%2Fwebapp-python-oracledb-flask-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foracle-quickstart%2Fwebapp-python-oracledb-flask-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foracle-quickstart%2Fwebapp-python-oracledb-flask-api/lists"}