{"library":"newsapi-python","title":"NewsAPI Python Client","description":"An unofficial Python client for the News API. It provides a simple, object-oriented interface to access the News API V2 endpoints (/top-headlines, /everything, and /sources) for programmatically retrieving live articles from news sources and blogs. The current version is 0.2.7.","language":"python","status":"maintenance","last_verified":"Thu Apr 16","install":{"commands":["pip install newsapi-python"],"cli":null},"imports":["from newsapi import NewsApiClient"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom newsapi import NewsApiClient\n\n# Your API key from newsapi.org. Use environment variables for production.\napi_key = os.environ.get('NEWSAPI_API_KEY', 'YOUR_API_KEY_HERE')\n\nif api_key == 'YOUR_API_KEY_HERE':\n    print(\"WARNING: Replace 'YOUR_API_KEY_HERE' with your actual NewsAPI key or set the NEWSAPI_API_KEY environment variable.\")\n    print(\"You can get a free API key at https://newsapi.org/\")\n    # Exit or handle this case appropriately in a real application\n    exit()\n\nnewsapi = NewsApiClient(api_key=api_key)\n\n# Get top headlines in the US\ntop_headlines = newsapi.get_top_headlines(q='bitcoin', language='en', country='us')\nprint(f\"Top headlines: {len(top_headlines.get('articles', []))} articles\")\n\n# Get all articles about Tesla from BBC News\nall_articles = newsapi.get_everything(q='tesla',\n                                      sources='bbc-news,the-verge',\n                                      language='en',\n                                      sort_by='relevancy')\nprint(f\"All articles: {len(all_articles.get('articles', []))} articles\")\n\n# Get available news sources\nsources = newsapi.get_sources(category='technology', language='en', country='us')\nprint(f\"Available sources: {len(sources.get('sources', []))} sources\")\n\n# Print a sample article title (if available)\nif top_headlines.get('articles'):\n    print(f\"\\nSample top headline: {top_headlines['articles'][0].get('title')}\")","lang":"python","description":"Initializes the NewsApiClient with your API key and demonstrates how to fetch top headlines, all articles matching a query, and available news sources.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}