{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-guides/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Sample Python Web Application","description":"Accelerate E&P application development and protect your innovation by consuming our Data and Domain APIs / Platform APIs.","lang":"en-US","meta":[{"name":"robots","content":"noindex"}],"llmstxt":{"hide":true,"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"sample-python-web-application","__idx":0},"children":["Sample Python Web Application"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This sample code demonstrates how to obtain an ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/cloud-apis/create-first-app/concepts#access-token"},"children":["Access token"]}," using the SLB Authenticator service for a  ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/cloud-apis/create-first-app/concepts#confidential-client"},"children":["Confidential client"]}," using an ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://oauth.net/2/grant-types/authorization-code/"},"children":["Authorization Code Flow (ACF)"]}," grant using Python ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://flask.palletsprojects.com/en/2.2.x/"},"children":["Flask"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["NOTE : For demonstration, this sample retrieves the access token when you click on \"Get Access Token\" button."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"code-sample","__idx":1},"children":["Code sample"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/assets/getting_started_pythonccgsample.fd10c3777c5292f465476ebe7018b77e30aa3557397ad882ae547ad5df83f878.ebe4f9c4.zip"},"children":["PythonCCGSample.zip"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"pre-requisites","__idx":2},"children":["Pre-requisites"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Access to ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developer.delfi.slb.com/"},"children":["SLB Developer Portal"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["You need to be a member of a team on SLB Developer."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://www.python.org/"},"children":["Python 3.x"]}," is required."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://code.visualstudio.com/"},"children":["VS Code"]}," and ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://marketplace.visualstudio.com/items?itemName=ms-python.python"},"children":["Python Extension"]}," for VS Code."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"installation","__idx":3},"children":["Installation"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Unzip the sample code: PythonCCGSample.zip"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Open the root directory (containing app.py) of the unzipped sample code, in ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["Visual Studio Code"]}," editor. If you are new to running the Python code using ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["Visual Studio Code"]}," editor, refer ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://code.visualstudio.com/docs/python/python-quick-start"},"children":["quick start"]}," guide."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["We recommend that you create a virtual environment to work with the code samples."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Refer to ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://code.visualstudio.com/docs/python/environments#_using-the-create-environment-command"},"children":["Creation of virtual environments in VS Code"]}," for more details. This sample is tested for using \"Venv\" environment type."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Make sure above created environment in activated in VS Code. The selected interpreter version will show on the right side of the status bar of ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["Visual Studio Code"]}," editor, as shown below (python version might be different depending on your python installation). If not, refer to ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment"},"children":["select and activate an environment"]}," for details."," ",{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/environment-in-status-bar.e22ff963cc8c9e5d44d16912c0196641acb77846a44e1f7c6c8f77cbcc503d58.ab5388e2.jpeg","alt":"status bar"},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Make sure that your pip package installer is up-to-date:"]}]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    python -m pip install --upgrade pip\n"},"children":[]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Install the requirements.txt file:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    pip install -r requirements.txt\n"},"children":[]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Open app.py file and make the following changes:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["a. On line 8, set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CLIENT_ID = \"[YOUR CLIENT ID]\""]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["b. On line 9, set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CLIENT_SECRET = \"[YOUR CLIENT SECRET]\""]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Note:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Refer ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/create-client#create-clients-for-service-accounts"},"children":["creation of client"]}," for using as service account for details."]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Save the changes into app.py file."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Run application using the following command in Python terminal of VS Code"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    python -m flask run \n"},"children":[]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In your web browser, go to ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["http://127.0.0.1:{port}"]},". Replace ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{port}"]}," value with actual port value on which Flask application will run. The default port for the Flask application is 5000."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Click on \"Get Access Token\" button on home page"," ",{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/ccg-welcomepage.9111b26aaf020791b6ade768eedd4fa84e2059684da8e3cd0a0c784e93ad62bd.ab5388e2.jpeg","alt":"welcome page"},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Server side python code will use client id and client secret and will show the access token on web page."," ",{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/ccgtoken.26357194557a133c66c0dbbc28431dd81e15f39a581ad217a8c00c520a5c239b.ab5388e2.jpeg","alt":"access token"},"children":[]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"recommended-further-reading","__idx":4},"children":["Recommended further Reading"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/solutions/ccm/tutorial/user-context-service"},"children":["User context"]}," in SLB Digital platform"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/solutions/sauth/tutorial/secret-management-service"},"children":["Secret management"]}," on SLB Digital platform"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/cloud-apis/references/api-lifecycle"},"children":["API Maturity"]}," of cloud APIs"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Refer tutorial of various solutions (e.g. ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/solutions/fdplan/tutorial/about"},"children":["FDPlan"]},", ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/solutions/drillplan/docs/tutorials/tutorial"},"children":["DrillPlan"]},", ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/solutions/core-service/tutorial/osdu-core-services-about"},"children":["MPDF"]}," etc.) to learn more about their extensibility and how to integrate with APIs offered by these solutions into your application."]}]}]},"headings":[{"value":"Sample Python Web Application","id":"sample-python-web-application","depth":1},{"value":"Code sample","id":"code-sample","depth":2},{"value":"Pre-requisites","id":"pre-requisites","depth":2},{"value":"Installation","id":"installation","depth":2},{"value":"Recommended further Reading","id":"recommended-further-reading","depth":2}],"frontmatter":{"seo":{"title":"Sample Python Web Application"}},"lastModified":"2025-05-21T17:18:56.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/guides/cloud-apis/create-first-app/python-webapp-ccg-sample","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}