QVeris
QVERIS · PYTHON INTEGRATION

Stock API for Python: Get Quotes with QVeris

Connect Python to stock data with QVeris. Inspect a quote tool, send a request, save the JSON response, and start with signup trial credits.

Published: · Produced by the QVeris Team

Your first Python request — illustrative background for Stock API for Python: Get Quotes with QVeris; not a live data result.
QVERIS · DATA IN USE
Your first Python request

Inspect. Call. Save.

Connect your Python project to stock data

QVeris gives a Python application a route to discover and call stock data tools. Start with a single quote request, save the JSON response, and build your own output table from the returned fields. The same workflow can later support a notebook, a scheduled research script or a backend for a watchlist.

This example uses the Finnhub stock quote capability exposed through QVeris. The task is deliberately small: inspect the route, send one symbol, and keep the response for review. You do not need to select a model or build a full AI agent to make a direct data request.

The QVeris documentation also provides SDK integration paths. Direct HTTP is useful for a first request because the authentication, parameters and response are visible in one place.

Prepare the key and Python environment

Create a QVeris API key in your account and make it available to your process as QVERIS_API_KEY. Keep it in a local environment or a server-side secret store. Install requests in your project’s virtual environment, then save the example as stock_quote.py.

bash
python -m pip install requests
python stock_quote.py AAPL

The script reads the key at runtime; it contains no credentials. Run it on a backend or your own machine. A public browser page is not an appropriate place for an account API key. Before executing, review the tool details and current call pricing because execution can consume credits.

Inspect the route, then make one request

The example below checks that the selected route still accepts a string symbol and has no additional required fields before sending the request. It then saves the execution envelope rather than assuming every provider returns an identical quote object. Expand the code to copy the complete script.

Open complete Python example
python
"""Inspect and execute one stock quote route. Running this may use QVeris credits."""
import json
import os
import sys
from pathlib import Path
import requests

BASE = "https://qveris.ai/api/v1"
TOOL = "finnhub_io_api.stock.quote"

def post(path, body, key, query=None):
    response = requests.post(
        BASE + path,
        headers={"Authorization": "Bearer " + key},
        params=query,
        json=body,
        timeout=5,
    )
    response.raise_for_status()
    payload = response.json()
    if not isinstance(payload, dict) or payload.get("success") is False:
        raise ValueError("QVeris returned an unsuccessful or unexpected response")
    return payload

def main():
    key = os.environ["QVERIS_API_KEY"]
    symbol = sys.argv[1] if len(sys.argv) > 1 else "AAPL"
    inspected = post("/tools/by-ids", {"tool_ids": [TOOL]}, key)
    match = next((t for t in inspected.get("results", []) if t.get("tool_id") == TOOL), None)
    if not match:
        raise ValueError("Selected route is unavailable; inspect another route")
    fields = match.get("params") or []
    if not any(p.get("name") == "symbol" and p.get("type") == "string" for p in fields):
        raise ValueError("The symbol contract changed; review the tool before calling")
    if any(p.get("required") and p.get("name") != "symbol" for p in fields):
        raise ValueError("New required parameters need review")
    result = post("/tools/execute", {
        "parameters": {"symbol": symbol}, "max_response_size": 20480
    }, key, {"tool_id": TOOL})
    if result.get("success") is not True or result.get("result") is None:
        raise ValueError("Execution did not return a result")
    Path("quote-response.json").write_text(json.dumps(result, indent=2), encoding="utf-8")
    print("Saved quote-response.json. Validate provider data and timestamps before display.")

if __name__ == "__main__":
    try:
        main()
    except (KeyError, ValueError, OSError, requests.RequestException) as error:
        # Avoid printing authorization headers or complete provider responses.
        raise SystemExit("Request stopped: " + type(error).__name__) from None

The example uses a five-second Requests timeout and stops on HTTP, JSON or execution errors. Requests timeouts describe connection/read waiting behavior, not a guaranteed total wall-clock deadline. See the Requests timeout documentation. A slow response can fail this example even when the tool itself is available.

Read the saved response before automating

Open quote-response.json and locate the provider payload within the execution result. Confirm a successful provider response, a matching instrument and a meaningful observation timestamp. An outer success flag describes execution; it cannot by itself prove that a provider returned usable market data.

Do not translate an empty object into a zero-dollar stock. Likewise, do not flatten a truncated response into a complete dataset. The stock API JSON guide explains how to keep execution metadata separate from your application’s normalized data model.

Keep the original response file during development. A derived table is convenient for users, while the raw object helps you diagnose a renamed field, a missing currency or a change in upstream error formatting.

Add the next data task when you need it

After the single-symbol request works, add a small list of tickers and handle each outcome separately. Use bounded retries for eligible transient failures and avoid immediate retry loops. An execution timeout may leave the final outcome uncertain, so check available execution or usage records before blindly repeating a billed call.

Choose a historical stock data capability for dated bars, or a company profile capability for names and exchange context. Inspect each new route: the quote parameter symbol is not a universal schema for every stock tool. Keep symbol lists, date windows and schedules in your application configuration.

Frequently asked questions

Is the script a live benchmark?

No. It is an integration example using an inspected tool contract. Actual data, availability and charges depend on your execution and account access.

Do I need an LLM key for this example?

No. This script makes direct QVeris data requests. A model key is relevant when you separately build an agent or model-driven workflow.

Inspect the quote tool and prepare Python integration

Open the prefilled QVeris task to inspect the AAPL quote parameters and, when callable, retrieve one result. The output will include the returned fields, source time and a Python checklist for environment variables, error handling and response storage—without exposing an API key.

Use QVeris to inspect the AAPL stock quote capability and explain its current parameter contract. Then, if callable, retrieve one quote and show the source time and returned fields. Provide a short Python integration checklist covering environment variables, HTTP errors, provider errors and response storage. Do not include any API key. Respond in English.

Beyond a Python quote: more market-data workflows