[{"data":1,"prerenderedAt":1090},["ShallowReactive",2],{"page-\u002Fgetting-started-with-python-apis-for-builders\u002Fmaking-http-requests-with-requests-library\u002F":3,"faq-schema-\u002Fgetting-started-with-python-apis-for-builders\u002Fmaking-http-requests-with-requests-library\u002F":1072},{"id":4,"title":5,"body":6,"description":16,"extension":1066,"meta":1067,"navigation":192,"path":1068,"seo":1069,"stem":1070,"__hash__":1071},"content\u002Fgetting-started-with-python-apis-for-builders\u002Fmaking-http-requests-with-requests-library\u002Findex.md","Making HTTP Requests with the Requests Library: A Builder’s Integration Guide",{"type":7,"value":8,"toc":1056},"minimark",[9,13,17,22,25,82,91,95,102,130,651,655,658,682,686,689,731,904,911,915,918,952,960,964,992,996,1005,1014,1027,1040,1044,1052],[10,11,5],"h1",{"id":12},"making-http-requests-with-the-requests-library-a-builders-integration-guide",[14,15,16],"p",{},"Mastering making HTTP requests with requests library is the foundational step for builders integrating third-party services. This guide walks you through production-ready client architecture, emphasizing cost-aware payload design, robust error handling, and scalable session management. Whether you are prototyping a side-hustle or scaling a startup, these patterns ensure reliable data exchange while minimizing infrastructure overhead.",[18,19,21],"h2",{"id":20},"_1-initializing-the-integration-environment","1. Initializing the Integration Environment",[14,23,24],{},"Before writing client logic, establish a reproducible, dependency-pinned workspace for safe API experimentation. Uncontrolled dependency drift causes silent failures in production and inflates debugging costs.",[26,27,28,45,69],"ul",{},[29,30,31,35,36,40,41,44],"li",{},[32,33,34],"strong",{},"Virtual environment isolation:"," Always run API integrations inside a dedicated ",[37,38,39],"code",{},"venv"," or ",[37,42,43],{},"pipenv"," environment to prevent system-wide package conflicts.",[29,46,47,58,59,62,63,65,66,68],{},[32,48,49,50,53,54,57],{},"Pin ",[37,51,52],{},"requests"," and ",[37,55,56],{},"urllib3",":"," Lock exact versions in ",[37,60,61],{},"requirements.txt",". The ",[37,64,52],{}," library relies heavily on ",[37,67,56],{}," for connection pooling; mismatched versions introduce unpredictable retry behavior.",[29,70,71,74,75,40,78,81],{},[32,72,73],{},"Environment variable configuration:"," Never commit credentials to version control. Load secrets via ",[37,76,77],{},"os.environ",[37,79,80],{},"python-dotenv"," at runtime.",[14,83,84,85,90],{},"For a complete walkthrough of workspace isolation and dependency management during the integrate phase, reference ",[86,87,89],"a",{"href":88},"\u002Fgetting-started-with-python-apis-for-builders\u002F","Getting Started with Python APIs for Builders",".",[18,92,94],{"id":93},"_2-architecting-a-cost-aware-http-client","2. Architecting a Cost-Aware HTTP Client",[14,96,97,98,101],{},"Repeatedly calling ",[37,99,100],{},"requests.get()"," creates a new TCP handshake per request. This overhead drains CPU, exhausts ephemeral ports, and increases cloud infrastructure costs. A production client must reuse connections and enforce strict boundaries.",[26,103,104,114,120],{},[29,105,106,109,110,113],{},[32,107,108],{},"Connection pooling:"," ",[37,111,112],{},"requests.Session()"," maintains a persistent connection pool, drastically reducing latency for sequential calls.",[29,115,116,119],{},[32,117,118],{},"Explicit timeouts:"," Always separate connect and read timeouts. A missing timeout blocks threads indefinitely, causing memory leaks and hidden compute charges.",[29,121,122,125,126,129],{},[32,123,124],{},"Disable auto-redirects:"," Set ",[37,127,128],{},"allow_redirects=False"," to prevent unexpected bandwidth consumption and ensure predictable payload routing.",[131,132,137],"pre",{"className":133,"code":134,"language":135,"meta":136,"style":136},"language-python shiki shiki-themes github-light github-dark","import os\nimport requests\nfrom requests.adapters import HTTPAdapter\nfrom urllib3.util.retry import Retry\n\n# Initialize a reusable session\nsession = requests.Session()\n\n# Configure exponential backoff for transient server errors\nretry_strategy = Retry(\n total=3,\n backoff_factor=0.5,\n status_forcelist=[500, 502, 503, 504, 429],\n allowed_methods=[\"GET\", \"POST\", \"PUT\"]\n)\nadapter = HTTPAdapter(max_retries=retry_strategy)\nsession.mount(\"https:\u002F\u002F\", adapter)\n\n# Set baseline headers and authentication\nsession.headers.update({\n \"Accept\": \"application\u002Fjson\",\n \"User-Agent\": \"BuilderClient\u002F1.0\",\n \"Authorization\": f\"Bearer {os.getenv('API_KEY')}\"\n})\n\ntry:\n # (connect_timeout, read_timeout) prevents thread blocking\n response = session.get(\"https:\u002F\u002Fapi.example.com\u002Fdata\", timeout=(3.05, 10))\n response.raise_for_status()\n payload = response.json()\n print(\"Data retrieved successfully.\")\nexcept requests.exceptions.Timeout:\n print(\"Request timed out. Check provider status or network.\")\nexcept requests.exceptions.HTTPError as e:\n print(f\"HTTP error: {e.response.status_code} - {e.response.text}\")\nexcept requests.exceptions.RequestException as e:\n print(f\"Request failed: {e}\")\nfinally:\n session.close()\n","python","",[37,138,139,152,160,174,187,194,201,213,218,224,235,251,264,302,329,335,354,366,371,377,383,397,410,442,448,453,462,468,503,509,520,533,542,554,568,602,614,637,645],{"__ignoreMap":136},[140,141,144,148],"span",{"class":142,"line":143},"line",1,[140,145,147],{"class":146},"szBVR","import",[140,149,151],{"class":150},"sVt8B"," os\n",[140,153,155,157],{"class":142,"line":154},2,[140,156,147],{"class":146},[140,158,159],{"class":150}," requests\n",[140,161,163,166,169,171],{"class":142,"line":162},3,[140,164,165],{"class":146},"from",[140,167,168],{"class":150}," requests.adapters ",[140,170,147],{"class":146},[140,172,173],{"class":150}," HTTPAdapter\n",[140,175,177,179,182,184],{"class":142,"line":176},4,[140,178,165],{"class":146},[140,180,181],{"class":150}," urllib3.util.retry ",[140,183,147],{"class":146},[140,185,186],{"class":150}," Retry\n",[140,188,190],{"class":142,"line":189},5,[140,191,193],{"emptyLinePlaceholder":192},true,"\n",[140,195,197],{"class":142,"line":196},6,[140,198,200],{"class":199},"sJ8bj","# Initialize a reusable session\n",[140,202,204,207,210],{"class":142,"line":203},7,[140,205,206],{"class":150},"session ",[140,208,209],{"class":146},"=",[140,211,212],{"class":150}," requests.Session()\n",[140,214,216],{"class":142,"line":215},8,[140,217,193],{"emptyLinePlaceholder":192},[140,219,221],{"class":142,"line":220},9,[140,222,223],{"class":199},"# Configure exponential backoff for transient server errors\n",[140,225,227,230,232],{"class":142,"line":226},10,[140,228,229],{"class":150},"retry_strategy ",[140,231,209],{"class":146},[140,233,234],{"class":150}," Retry(\n",[140,236,238,242,244,248],{"class":142,"line":237},11,[140,239,241],{"class":240},"s4XuR"," total",[140,243,209],{"class":146},[140,245,247],{"class":246},"sj4cs","3",[140,249,250],{"class":150},",\n",[140,252,254,257,259,262],{"class":142,"line":253},12,[140,255,256],{"class":240}," backoff_factor",[140,258,209],{"class":146},[140,260,261],{"class":246},"0.5",[140,263,250],{"class":150},[140,265,267,270,272,275,278,281,284,286,289,291,294,296,299],{"class":142,"line":266},13,[140,268,269],{"class":240}," status_forcelist",[140,271,209],{"class":146},[140,273,274],{"class":150},"[",[140,276,277],{"class":246},"500",[140,279,280],{"class":150},", ",[140,282,283],{"class":246},"502",[140,285,280],{"class":150},[140,287,288],{"class":246},"503",[140,290,280],{"class":150},[140,292,293],{"class":246},"504",[140,295,280],{"class":150},[140,297,298],{"class":246},"429",[140,300,301],{"class":150},"],\n",[140,303,305,308,310,312,316,318,321,323,326],{"class":142,"line":304},14,[140,306,307],{"class":240}," allowed_methods",[140,309,209],{"class":146},[140,311,274],{"class":150},[140,313,315],{"class":314},"sZZnC","\"GET\"",[140,317,280],{"class":150},[140,319,320],{"class":314},"\"POST\"",[140,322,280],{"class":150},[140,324,325],{"class":314},"\"PUT\"",[140,327,328],{"class":150},"]\n",[140,330,332],{"class":142,"line":331},15,[140,333,334],{"class":150},")\n",[140,336,338,341,343,346,349,351],{"class":142,"line":337},16,[140,339,340],{"class":150},"adapter ",[140,342,209],{"class":146},[140,344,345],{"class":150}," HTTPAdapter(",[140,347,348],{"class":240},"max_retries",[140,350,209],{"class":146},[140,352,353],{"class":150},"retry_strategy)\n",[140,355,357,360,363],{"class":142,"line":356},17,[140,358,359],{"class":150},"session.mount(",[140,361,362],{"class":314},"\"https:\u002F\u002F\"",[140,364,365],{"class":150},", adapter)\n",[140,367,369],{"class":142,"line":368},18,[140,370,193],{"emptyLinePlaceholder":192},[140,372,374],{"class":142,"line":373},19,[140,375,376],{"class":199},"# Set baseline headers and authentication\n",[140,378,380],{"class":142,"line":379},20,[140,381,382],{"class":150},"session.headers.update({\n",[140,384,386,389,392,395],{"class":142,"line":385},21,[140,387,388],{"class":314}," \"Accept\"",[140,390,391],{"class":150},": ",[140,393,394],{"class":314},"\"application\u002Fjson\"",[140,396,250],{"class":150},[140,398,400,403,405,408],{"class":142,"line":399},22,[140,401,402],{"class":314}," \"User-Agent\"",[140,404,391],{"class":150},[140,406,407],{"class":314},"\"BuilderClient\u002F1.0\"",[140,409,250],{"class":150},[140,411,413,416,418,421,424,427,430,433,436,439],{"class":142,"line":412},23,[140,414,415],{"class":314}," \"Authorization\"",[140,417,391],{"class":150},[140,419,420],{"class":146},"f",[140,422,423],{"class":314},"\"Bearer ",[140,425,426],{"class":246},"{",[140,428,429],{"class":150},"os.getenv(",[140,431,432],{"class":314},"'API_KEY'",[140,434,435],{"class":150},")",[140,437,438],{"class":246},"}",[140,440,441],{"class":314},"\"\n",[140,443,445],{"class":142,"line":444},24,[140,446,447],{"class":150},"})\n",[140,449,451],{"class":142,"line":450},25,[140,452,193],{"emptyLinePlaceholder":192},[140,454,456,459],{"class":142,"line":455},26,[140,457,458],{"class":146},"try",[140,460,461],{"class":150},":\n",[140,463,465],{"class":142,"line":464},27,[140,466,467],{"class":199}," # (connect_timeout, read_timeout) prevents thread blocking\n",[140,469,471,474,476,479,482,484,487,489,492,495,497,500],{"class":142,"line":470},28,[140,472,473],{"class":150}," response ",[140,475,209],{"class":146},[140,477,478],{"class":150}," session.get(",[140,480,481],{"class":314},"\"https:\u002F\u002Fapi.example.com\u002Fdata\"",[140,483,280],{"class":150},[140,485,486],{"class":240},"timeout",[140,488,209],{"class":146},[140,490,491],{"class":150},"(",[140,493,494],{"class":246},"3.05",[140,496,280],{"class":150},[140,498,499],{"class":246},"10",[140,501,502],{"class":150},"))\n",[140,504,506],{"class":142,"line":505},29,[140,507,508],{"class":150}," response.raise_for_status()\n",[140,510,512,515,517],{"class":142,"line":511},30,[140,513,514],{"class":150}," payload ",[140,516,209],{"class":146},[140,518,519],{"class":150}," response.json()\n",[140,521,523,526,528,531],{"class":142,"line":522},31,[140,524,525],{"class":246}," print",[140,527,491],{"class":150},[140,529,530],{"class":314},"\"Data retrieved successfully.\"",[140,532,334],{"class":150},[140,534,536,539],{"class":142,"line":535},32,[140,537,538],{"class":146},"except",[140,540,541],{"class":150}," requests.exceptions.Timeout:\n",[140,543,545,547,549,552],{"class":142,"line":544},33,[140,546,525],{"class":246},[140,548,491],{"class":150},[140,550,551],{"class":314},"\"Request timed out. Check provider status or network.\"",[140,553,334],{"class":150},[140,555,557,559,562,565],{"class":142,"line":556},34,[140,558,538],{"class":146},[140,560,561],{"class":150}," requests.exceptions.HTTPError ",[140,563,564],{"class":146},"as",[140,566,567],{"class":150}," e:\n",[140,569,571,573,575,577,580,582,585,587,590,592,595,597,600],{"class":142,"line":570},35,[140,572,525],{"class":246},[140,574,491],{"class":150},[140,576,420],{"class":146},[140,578,579],{"class":314},"\"HTTP error: ",[140,581,426],{"class":246},[140,583,584],{"class":150},"e.response.status_code",[140,586,438],{"class":246},[140,588,589],{"class":314}," - ",[140,591,426],{"class":246},[140,593,594],{"class":150},"e.response.text",[140,596,438],{"class":246},[140,598,599],{"class":314},"\"",[140,601,334],{"class":150},[140,603,605,607,610,612],{"class":142,"line":604},36,[140,606,538],{"class":146},[140,608,609],{"class":150}," requests.exceptions.RequestException ",[140,611,564],{"class":146},[140,613,567],{"class":150},[140,615,617,619,621,623,626,628,631,633,635],{"class":142,"line":616},37,[140,618,525],{"class":246},[140,620,491],{"class":150},[140,622,420],{"class":146},[140,624,625],{"class":314},"\"Request failed: ",[140,627,426],{"class":246},[140,629,630],{"class":150},"e",[140,632,438],{"class":246},[140,634,599],{"class":314},[140,636,334],{"class":150},[140,638,640,643],{"class":142,"line":639},38,[140,641,642],{"class":146},"finally",[140,644,461],{"class":150},[140,646,648],{"class":142,"line":647},39,[140,649,650],{"class":150}," session.close()\n",[18,652,654],{"id":653},"_3-implementing-resilient-error-handling-retries","3. Implementing Resilient Error Handling & Retries",[14,656,657],{},"Silent failures corrupt data pipelines and waste API quotas. Structured exception routing ensures your application degrades gracefully instead of crashing or retrying blindly.",[26,659,660,666,676],{},[29,661,662,665],{},[32,663,664],{},"Route 4xx vs 5xx:"," Client errors (4xx) indicate bad payloads or invalid auth. Do not retry these; log and alert immediately. Server errors (5xx) indicate provider instability; retry with backoff.",[29,667,668,671,672,675],{},[32,669,670],{},"Exponential backoff with jitter:"," The ",[37,673,674],{},"urllib3.util.Retry"," configuration above handles this automatically. Jitter prevents thundering herd scenarios when multiple clients retry simultaneously.",[29,677,678,681],{},[32,679,680],{},"Circuit breaker patterns:"," Track consecutive failures. If a provider exceeds your error threshold, halt requests for a cooldown period to avoid billing spikes and IP bans.",[18,683,685],{"id":684},"_4-optimizing-payloads-rate-limit-compliance","4. Optimizing Payloads & Rate Limit Compliance",[14,687,688],{},"API providers charge by request volume or data transfer. Unoptimized clients trigger throttling, incur overage fees, and risk account suspension.",[26,690,691,707,725],{},[29,692,693,696,697,53,700,703,704,90],{},[32,694,695],{},"Parse rate-limit headers proactively:"," Monitor ",[37,698,699],{},"X-RateLimit-Remaining",[37,701,702],{},"X-RateLimit-Reset"," to throttle requests before hitting ",[37,705,706],{},"429 Too Many Requests",[29,708,709,716,717,720,721,724],{},[32,710,711,712,715],{},"Use ",[37,713,714],{},"json="," parameter:"," Passing a dictionary to ",[37,718,719],{},"session.post(url, json=payload)"," automatically serializes to JSON and sets ",[37,722,723],{},"Content-Type: application\u002Fjson",", reducing manual overhead and serialization bugs.",[29,726,727,730],{},[32,728,729],{},"Token-bucket delays:"," Implement dynamic sleep intervals between high-volume calls to stay within provider windows.",[131,732,734],{"className":133,"code":733,"language":135,"meta":136,"style":136},"import time\nimport requests\n\ndef fetch_with_rate_limit(url, session):\n resp = session.get(url)\n resp.raise_for_status()\n \n # Proactively parse rate limit headers\n remaining = int(resp.headers.get(\"X-RateLimit-Remaining\", 1))\n if remaining \u003C= 2:\n reset_time = float(resp.headers.get(\"X-RateLimit-Reset\", 60))\n print(f\"Approaching limit. Sleeping for {reset_time}s.\")\n time.sleep(reset_time)\n \n return resp.json()\n\n# Usage aligns with standard protocol selection and payload structuring.\n# Review Understanding REST vs GraphQL to ensure your HTTP methods match provider expectations.\n",[37,735,736,743,749,753,765,775,780,785,790,813,828,850,873,878,882,890,894,899],{"__ignoreMap":136},[140,737,738,740],{"class":142,"line":143},[140,739,147],{"class":146},[140,741,742],{"class":150}," time\n",[140,744,745,747],{"class":142,"line":154},[140,746,147],{"class":146},[140,748,159],{"class":150},[140,750,751],{"class":142,"line":162},[140,752,193],{"emptyLinePlaceholder":192},[140,754,755,758,762],{"class":142,"line":176},[140,756,757],{"class":146},"def",[140,759,761],{"class":760},"sScJk"," fetch_with_rate_limit",[140,763,764],{"class":150},"(url, session):\n",[140,766,767,770,772],{"class":142,"line":189},[140,768,769],{"class":150}," resp ",[140,771,209],{"class":146},[140,773,774],{"class":150}," session.get(url)\n",[140,776,777],{"class":142,"line":196},[140,778,779],{"class":150}," resp.raise_for_status()\n",[140,781,782],{"class":142,"line":203},[140,783,784],{"class":150}," \n",[140,786,787],{"class":142,"line":215},[140,788,789],{"class":199}," # Proactively parse rate limit headers\n",[140,791,792,795,797,800,803,806,808,811],{"class":142,"line":220},[140,793,794],{"class":150}," remaining ",[140,796,209],{"class":146},[140,798,799],{"class":246}," int",[140,801,802],{"class":150},"(resp.headers.get(",[140,804,805],{"class":314},"\"X-RateLimit-Remaining\"",[140,807,280],{"class":150},[140,809,810],{"class":246},"1",[140,812,502],{"class":150},[140,814,815,818,820,823,826],{"class":142,"line":226},[140,816,817],{"class":146}," if",[140,819,794],{"class":150},[140,821,822],{"class":146},"\u003C=",[140,824,825],{"class":246}," 2",[140,827,461],{"class":150},[140,829,830,833,835,838,840,843,845,848],{"class":142,"line":237},[140,831,832],{"class":150}," reset_time ",[140,834,209],{"class":146},[140,836,837],{"class":246}," float",[140,839,802],{"class":150},[140,841,842],{"class":314},"\"X-RateLimit-Reset\"",[140,844,280],{"class":150},[140,846,847],{"class":246},"60",[140,849,502],{"class":150},[140,851,852,854,856,858,861,863,866,868,871],{"class":142,"line":253},[140,853,525],{"class":246},[140,855,491],{"class":150},[140,857,420],{"class":146},[140,859,860],{"class":314},"\"Approaching limit. Sleeping for ",[140,862,426],{"class":246},[140,864,865],{"class":150},"reset_time",[140,867,438],{"class":246},[140,869,870],{"class":314},"s.\"",[140,872,334],{"class":150},[140,874,875],{"class":142,"line":266},[140,876,877],{"class":150}," time.sleep(reset_time)\n",[140,879,880],{"class":142,"line":304},[140,881,784],{"class":150},[140,883,884,887],{"class":142,"line":331},[140,885,886],{"class":146}," return",[140,888,889],{"class":150}," resp.json()\n",[140,891,892],{"class":142,"line":337},[140,893,193],{"emptyLinePlaceholder":192},[140,895,896],{"class":142,"line":356},[140,897,898],{"class":199},"# Usage aligns with standard protocol selection and payload structuring.\n",[140,900,901],{"class":142,"line":368},[140,902,903],{"class":199},"# Review Understanding REST vs GraphQL to ensure your HTTP methods match provider expectations.\n",[14,905,906,907,90],{},"For advanced throughput management and quota optimization strategies, consult ",[86,908,910],{"href":909},"\u002Fgetting-started-with-python-apis-for-builders\u002Fmaking-http-requests-with-requests-library\u002Fbest-practices-for-api-rate-limiting\u002F","Best practices for API rate limiting",[18,912,914],{"id":913},"_5-local-testing-mock-integration","5. Local Testing & Mock Integration",[14,916,917],{},"Deploying untested HTTP clients to production guarantees downtime. Validate resilience against simulated latency, network drops, and provider outages before scaling.",[26,919,920,930,942],{},[29,921,922,929],{},[32,923,924,925,928],{},"Use the ",[37,926,927],{},"responses"," library:"," Mock HTTP endpoints deterministically without spinning up external services.",[29,931,932,935,936,53,939,941],{},[32,933,934],{},"Simulate failure states:"," Inject ",[37,937,938],{},"503 Service Unavailable",[37,940,706],{}," responses to verify your retry logic and backoff timers.",[29,943,944,947,948,951],{},[32,945,946],{},"Bridge to local backends:"," Route client requests to ",[37,949,950],{},"http:\u002F\u002Flocalhost:8000"," endpoints to validate data contracts before hitting live providers.",[14,953,954,955,959],{},"Once your client passes local validation, connect it to your application layer by following ",[86,956,958],{"href":957},"\u002Fgetting-started-with-python-apis-for-builders\u002Fsetting-up-fastapi\u002F","Setting Up FastAPI"," to build scalable, type-safe backend services.",[18,961,963],{"id":962},"common-mistakes","Common Mistakes",[26,965,966,972,975,978,985],{},[29,967,968,969,971],{},"Instantiating new ",[37,970,100],{}," calls per request, causing TCP handshake overhead and connection exhaustion.",[29,973,974],{},"Omitting timeout arguments, leading to indefinite thread blocking and hidden infrastructure costs.",[29,976,977],{},"Hardcoding API keys instead of using environment variables, creating security vulnerabilities and deployment failures.",[29,979,980,981,984],{},"Ignoring ",[37,982,983],{},"response.raise_for_status()",", which masks 4xx\u002F5xx errors and allows corrupted data to enter pipelines.",[29,986,987,988,991],{},"Failing to respect ",[37,989,990],{},"Retry-After"," headers, triggering aggressive throttling and potential account suspension.",[18,993,995],{"id":994},"faq","FAQ",[14,997,998,1001,1002,1004],{},[32,999,1000],{},"How do I prevent API costs from spiraling during development?","\nImplement strict timeout values, use ",[37,1003,112],{}," to reuse connections, and parse rate-limit headers to throttle requests before hitting paid tiers or overage charges.",[14,1006,1007,1010,1011,1013],{},[32,1008,1009],{},"What is the most reliable way to handle 429 Too Many Requests?","\nRead the ",[37,1012,990],{}," header, implement exponential backoff with jitter, and pause execution until the reset window expires rather than immediately retrying.",[14,1015,1016,1019,1020,1022,1023,1026],{},[32,1017,1018],{},"Should I use requests or httpx for async workflows?","\nStick to ",[37,1021,52],{}," for synchronous, blocking integrations where simplicity and stability are prioritized. Migrate to ",[37,1024,1025],{},"httpx"," only when your architecture requires high-concurrency async event loops.",[14,1028,1029,1032,1033,1036,1037,90],{},[32,1030,1031],{},"How do I securely store API keys in production?","\nNever hardcode credentials. Use environment variables, secret managers (AWS Secrets Manager, Doppler), or ",[37,1034,1035],{},".env"," files explicitly excluded from version control via ",[37,1038,1039],{},".gitignore",[18,1041,1043],{"id":1042},"related-pages","Related Pages",[26,1045,1046],{},[29,1047,1048],{},[86,1049,1051],{"href":1050},"\u002Fgetting-started-with-python-apis-for-builders\u002Funderstanding-rest-vs-graphql\u002F","Understanding REST vs GraphQL",[1053,1054,1055],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}",{"title":136,"searchDepth":154,"depth":154,"links":1057},[1058,1059,1060,1061,1062,1063,1064,1065],{"id":20,"depth":154,"text":21},{"id":93,"depth":154,"text":94},{"id":653,"depth":154,"text":654},{"id":684,"depth":154,"text":685},{"id":913,"depth":154,"text":914},{"id":962,"depth":154,"text":963},{"id":994,"depth":154,"text":995},{"id":1042,"depth":154,"text":1043},"md",{},"\u002Fgetting-started-with-python-apis-for-builders\u002Fmaking-http-requests-with-requests-library",{"title":5,"description":16},"getting-started-with-python-apis-for-builders\u002Fmaking-http-requests-with-requests-library\u002Findex","_qoDZUBbDex3jQGZ_JG_PPkbM5-9pBuTg1jRH-RQAYQ",{"@context":1073,"@type":1074,"mainEntity":1075},"https:\u002F\u002Fschema.org","FAQPage",[1076,1081,1084,1087],{"@type":1077,"name":1000,"acceptedAnswer":1078},"Question",{"@type":1079,"text":1080},"Answer","Implement strict timeout values, use requests.Session() to reuse connections, and parse rate-limit headers to throttle requests before hitting paid tiers or overage charges.",{"@type":1077,"name":1009,"acceptedAnswer":1082},{"@type":1079,"text":1083},"Read the Retry-After header, implement exponential backoff with jitter, and pause execution until the reset window expires rather than immediately retrying.",{"@type":1077,"name":1018,"acceptedAnswer":1085},{"@type":1079,"text":1086},"Stick to requests for synchronous, blocking integrations where simplicity and stability are prioritized. Migrate to httpx only when your architecture requires high-concurrency async event loops.",{"@type":1077,"name":1031,"acceptedAnswer":1088},{"@type":1079,"text":1089},"Never hardcode credentials. Use environment variables, secret managers (AWS Secrets Manager, Doppler), or .env files explicitly excluded from version control via .gitignore.",1778017885595]