🔹 1. Reading Apps in Python

When you say “read apps”, I assume you mean:

  • Reading data from different sources (S3, Oracle DB, etc.)
  • Creating a simple API/app to expose or process that data.

In Python, “apps” often means either:

  • Command-line scripts (basic programs you run from terminal).
  • APIs (using frameworks like Flask or FastAPI).
  • Data apps/dashboards (using Streamlit, Dash, etc.).

🔹 2. Reading Data from S3 & Oracle in Python

✅ Reading from AWS S3

import boto3

# Create S3 client
s3 = boto3.client('s3')

# Download file from S3
bucket_name = "my-bucket"
key = "data/sample.csv"
local_file = "sample.csv"

s3.download_file(bucket_name, key, local_file)

print("File downloaded:", local_file)
  • You’ll need AWS credentials (~/.aws/credentials or environment variables).
  • You can also use s3fs or pandas directly for reading CSV/Parquet.
import pandas as pd

df = pd.read_csv("s3://my-bucket/data/sample.csv")
print(df.head())

✅ Reading from Oracle Database

You can use cx_Oracle or oracledb package.

import oracledb

# Connect to Oracle
conn = oracledb.connect(user="username", password="password", dsn="host:1521/service_name")

cursor = conn.cursor()
cursor.execute("SELECT * FROM employees WHERE ROWNUM <= 5")

for row in cursor:
    print(row)

cursor.close()
conn.close()

🔹 3. Creating a Simple API in Python

✅ Using Flask

from flask import Flask, jsonify
import pandas as pd

app = Flask(__name__)

@app.route("/s3data")
def get_s3_data():
    # Example: read CSV from S3 (requires credentials setup)
    df = pd.read_csv("s3://my-bucket/data/sample.csv")
    return jsonify(df.head(5).to_dict(orient="records"))

@app.route("/oracledata")
def get_oracle_data():
    import oracledb
    conn = oracledb.connect(user="username", password="password", dsn="host:1521/service_name")
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM employees WHERE ROWNUM <= 5")
    rows = [dict(zip([d[0] for d in cursor.description], row)) for row in cursor]
    conn.close()
    return jsonify(rows)

if __name__ == "__main__":
    app.run(debug=True)
  • Run with: python app.py
  • Open in browser: http://127.0.0.1:5000/s3data or /oracledata.

✅ Using FastAPI (better for modern apps & async)

from fastapi import FastAPI
import pandas as pd

app = FastAPI()

@app.get("/s3data")
def read_s3_data():
    df = pd.read_csv("s3://my-bucket/data/sample.csv")
    return df.head(5).to_dict(orient="records")

Run:

uvicorn app:app --reload

Open in browser: http://127.0.0.1:8000/s3data


✅ So the steps are:

  1. Read data (S3 → boto3/pandas, Oracle → cx_Oracle/oracledb).
  2. Create an API layer (Flask/FastAPI).
  3. Return JSON to consumers.

“where is the API name in the script?”

Let’s clarify with examples:


🔹 1. In Flask

When you write:

@app.route("/s3data")
def get_s3_data():
    ...
  • The API name (or endpoint path) is "/s3data".
  • The function name (get_s3_data) is the Python handler.
  • Full URL will be: http://127.0.0.1:5000/s3data

🔹 2. In FastAPI

When you write:

@app.get("/s3data")
def read_s3_data():
    ...
  • The API endpoint name is also "/s3data".
  • The method type is GET (you could also have @app.post, @app.put, etc.).
  • Full URL will be: http://127.0.0.1:8000/s3data

🔹 3. General Rule

In Python API frameworks:

  • The decorator (@app.route("/...") or @app.get("/...")) defines the API name / endpoint.
  • You can read it directly in the script to know what API is available.
  • Example: @app.get("/oracledata") means you can call: http://localhost:8000/oracledata

✅ So: the API name is the string inside the route decorator ("/s3data", "/oracledata", etc.), which maps a URL path to a function.


Pages: 1 2 3 4


Discover more from HintsToday

Subscribe to get the latest posts sent to your email.

Posted in

Discover more from HintsToday

Subscribe now to keep reading and get access to the full archive.

Continue reading