quickstart.md (2458B)
1 --- 2 label: Quick Start 3 order: 540 4 --- 5 6 # Quick Start 7 8 OSMA has fully open CORS and requires no authentication keys, so you can start fetching package data immediately — from a backend script, a CLI tool, or directly inside a browser application. 9 10 ## JavaScript (browser & Node.js) 11 12 CORS is fully open (`Access-Control-Allow-Origin: *`), so you can use the native `fetch` API directly. This example queries the NPM snapshot for `react`: 13 14 ```javascript 15 async function getPackageVersion(query) { 16 const url = `https://notamitgamer-osma-npm-api.hf.space/search?q=${encodeURIComponent(query)}&limit=1`; 17 18 try { 19 const response = await fetch(url); 20 if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); 21 22 const data = await response.json(); 23 if (data.results && data.results.length > 0) { 24 const pkg = data.results[0]; 25 console.log(`${pkg.name} | Version: ${pkg.version} | Rank: ${pkg.rank}`); 26 console.log(`Registry Link: ${pkg.url}`); 27 } else { 28 console.log("Package not found in the April 2026 snapshot."); 29 } 30 } catch (error) { 31 console.error("Failed to fetch OSMA data:", error); 32 } 33 } 34 35 getPackageVersion("react"); 36 ``` 37 38 ## Python 39 40 For Python apps, tools, or data analysis scripts, `requests` makes querying the PyPI snapshot simple: 41 42 ```python 43 import requests 44 45 def get_package_version(query): 46 url = f"https://notamitgamer-osma-pypi-api.hf.space/search?q={query}&limit=1" 47 try: 48 response = requests.get(url) 49 response.raise_for_status() 50 data = response.json() 51 52 if data.get("results"): 53 pkg = data["results"][0] 54 print(f"{pkg['name']} | Version: {pkg['version']} | Rank: {pkg['rank']}") 55 print(f"Registry Link: {pkg['url']}") 56 else: 57 print("Package not found in the April 2026 snapshot.") 58 59 except requests.exceptions.RequestException as e: 60 print(f"Failed to fetch OSMA data: {e}") 61 62 if __name__ == "__main__": 63 get_package_version("requests") 64 ``` 65 66 ## Command line (cURL) 67 68 Fastest way to test an endpoint from your terminal: 69 70 ```bash 71 curl -s "https://notamitgamer-osma-npm-api.hf.space/search?q=express&limit=3" | jq 72 ``` 73 74 !!!info Rate limits apply 75 These endpoints are subject to the standard free-tier rate limits (10 requests/minute, 100/hour). If you're writing a script that loops through hundreds of packages, you'll need an `X-Bypass-Token` — see [Utility Endpoints](utility.md). 76 !!!