{"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":"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_pythonwebappsample.ffc2b749d47230a1ffe588a4dd9a3d206bca10d7ae53430fdf6994cc2fb496ea.ebe4f9c4.zip"},"children":["PythonWebAppSample.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 the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developer.delfi.slb.com/"},"children":["SLB Developer Portal"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["You must be a member of a Team in the SLB Developer Portal."]},{"$$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":"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: PythonWebAppSample.zip."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Open the folder in VSCode or another IDE."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Navigate to the root directory of the unzipped sample code."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["We recommend that you create a virtual environment to work with the Python code samples."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following steps explain how to use venv, the built-in module in Python 3.3 and later versions, to create a virtual environment. If you use other tools such as virtualenv, pipenv, etc., refer to the documentation of the corresponding tool."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Refer to ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.python.org/3/library/venv.html"},"children":["venv — Creation of virtual environments"]}," for more information about how use venv in Python to create virtual environments."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","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":["Create the virtual environment in the current directory named .venv:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    python -m venv .venv\n"},"children":[]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Open the sample folder in VSCode or another editor. You may need to restart your IDE to activate the virtual environment."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Activate the virtual environment:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    .venv/Scripts/activate\n"},"children":[]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","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 /PythonWebAppSample/confidential_client.py  and make the following changes:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["a. On line 29, set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CLIENT_ID = \"[YOUR CLIENT ID]\""]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["b. On line 30, 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 to ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/create-client#create-clients-for-web-server-apps"},"children":["create client for web server app"]}," for details."]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"run-the-code-sample","__idx":4},"children":["Run the code sample"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This section provides the steps to run the sample Python code."]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Open a terminal session and navigate to the folder containing confidential_client.py."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    C:\\cd <path>\\PythonWebAppSample\n"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":2},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Run confidential_client.py using the following Python command:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"   Python confidential_client.py \n"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":3},"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://localhost:8080/"]}," ",{"$$mdtype":"Tag","name":"img","attributes":{"src":"https://dev.azure.com/slb-swt/openness/_git/Getting-Started?path=/delfi-docs/images/PythonWebAppSample-Login.PNG","alt":""},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["On the web page that appears, click ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Login"]},"."," ","The browser redirects to the log-in page. ",{"$$mdtype":"Tag","name":"br","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"br","attributes":{},"children":[]}," ",{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/delfi-login.1845ecb364800d7194290ab72a5f560b569266dbeab2aa11c087af4e9a29d402.ab5388e2.jpeg","alt":"Log-in"},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["After successful authentication, the browser redirects to the redirect URL provided by the client, in this example: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["http://localhost:8080/"]},"."," ",{"$$mdtype":"Tag","name":"br","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"br","attributes":{},"children":[]}," ",{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/pythonwebappsample-login.4bcbaf2a7a984222eaa30d7754a313f5aa369ce3aa6dc25e22d9b14a4c773351.ab5388e2.jpeg","alt":"Python-ACF"},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["SLB Authenticator issues an ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/cloud-apis/create-first-app/concepts#authorization-code-"},"children":["Authorization Code"]}," which you can exchange for an Access token by clicking the \"Exchange authorization code for tokens\" link. Note that the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/cloud-apis/create-first-app/concepts#authorization-code-"},"children":["Authorization Code"]}," can be used only once, and it expires within 10 minutes."," ",{"$$mdtype":"Tag","name":"br","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"br","attributes":{},"children":[]}," ",{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/pythonwebappsample-acf.01363cfa49e2d45e796a321bc7541fcd3504c52dade4f45e7db429234e78693f.ab5388e2.jpeg","alt":"Python-ACF-Login"},"children":[]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["http://localhost:8080/token"]}," displays the Access token."," ",{"$$mdtype":"Tag","name":"br","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"br","attributes":{},"children":[]}," ",{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/pythonsample-tokens.6e86d6265b8614ec386d4ea51352953f391b64888b404c709809d9eff4a5ee4c.ab5388e2.jpeg","alt":"Python-token"},"children":[]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"conclusion","__idx":5},"children":["Conclusion"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["By running this code sample, you have learned how to obtain an ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/guides/cloud-apis/create-first-app/concepts#access-token"},"children":["Access token"]}," required to access cloud APIs."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"next-steps","__idx":6},"children":["Next steps"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can access various cloud APIs (such as MPDF APIs or Drill Plan APIs) using this Access token."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"additional-resources","__idx":7},"children":["Additional resources"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.python.org/3/library/venv.html"},"children":["How to create a virtual environment in Python"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/create-client"},"children":["How to create a client for your App "]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"recommended-further-reading","__idx":8},"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 the SLB Digital Platform."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/solutions/sauth/tutorial/secret-management-service"},"children":["Secret management"]}," within the 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 to the tutorial of various solutions (such as ",{"$$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":"Run the code sample","id":"run-the-code-sample","depth":2},{"value":"Conclusion","id":"conclusion","depth":2},{"value":"Next steps","id":"next-steps","depth":2},{"value":"Additional resources","id":"additional-resources","depth":2},{"value":"Recommended further Reading","id":"recommended-further-reading","depth":2}],"frontmatter":{"seo":{"title":"Sample Python Web Application"}},"lastModified":"2025-06-05T20:49:22.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/guides/cloud-apis/create-first-app/python-webapp-sample","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}