Skip to content
gitpavleenbali edited this page Feb 17, 2026 · 2 revisions

fetch

The fetch module retrieves real-time data from various sources.

Import

from pyai.easy import fetch

Quick Start

from pyai.easy import fetch

# Get weather
weather = fetch.weather("New York")

# Get news
news = fetch.news("technology")

# Get stock price
stock = fetch.stock("AAPL")

Functions

Weather

weather = fetch.weather("San Francisco")
print(weather)
# {
#   "temperature": 72,
#   "condition": "Sunny",
#   "humidity": 45,
#   "wind": "10 mph"
# }

# With units
weather = fetch.weather("London", units="metric")

News

# Get news by topic
news = fetch.news("artificial intelligence")

# Get news by category
news = fetch.news(category="technology")

# Limit results
news = fetch.news("climate", limit=5)

Stocks

# Get stock price
stock = fetch.stock("AAPL")
print(stock)
# {
#   "symbol": "AAPL",
#   "price": 175.50,
#   "change": +2.30,
#   "change_percent": +1.33
# }

# Multiple stocks
stocks = fetch.stocks(["AAPL", "GOOGL", "MSFT"])

Crypto

# Get crypto price
btc = fetch.crypto("BTC")
print(btc)
# {
#   "symbol": "BTC",
#   "price": 45000.00,
#   "change_24h": +1200.00
# }

URL Content

# Fetch and parse web content
content = fetch.url("https://example.com/article")
print(content.text)
print(content.title)

Examples

Weather Dashboard

from pyai.easy import fetch

cities = ["New York", "London", "Tokyo"]
for city in cities:
    w = fetch.weather(city)
    print(f"{city}: {w['temperature']}Β°F - {w['condition']}")

News Aggregator

from pyai.easy import fetch

topics = ["AI", "climate", "space"]
for topic in topics:
    articles = fetch.news(topic, limit=3)
    print(f"\n{topic.upper()}:")
    for article in articles:
        print(f"  - {article['title']}")

Stock Tracker

from pyai.easy import fetch

portfolio = ["AAPL", "GOOGL", "MSFT", "AMZN"]
stocks = fetch.stocks(portfolio)

for stock in stocks:
    sign = "+" if stock['change'] > 0 else ""
    print(f"{stock['symbol']}: ${stock['price']:.2f} ({sign}{stock['change_percent']:.2f}%)")

Async Usage

import asyncio
from pyai.easy import fetch

async def main():
    weather = await fetch.weather_async("New York")
    news = await fetch.news_async("tech")
    print(weather, news)

asyncio.run(main())

See Also

🧠 PYAI Wiki

Home


πŸš€ Getting Started


πŸ’‘ Core Concepts


🎯 One-Liner APIs


πŸ€– Agent Framework


πŸ”— Multi-Agent


πŸ› οΈ Tools & Skills


🏒 Enterprise


πŸŽ™οΈ Voice


πŸ–ΌοΈ Multimodal


πŸ“Š Vector DB


🌐 OpenAPI


πŸ”Œ Plugins


🀝 A2A Protocol


πŸ”’ Security


πŸ“š Reference


Intelligence, Embedded.

Clone this wiki locally