Use this file to discover all available pages before exploring further.
In this tutorial, you’ll learn how to build a real-time company intelligence system that automatically gathers and structures information about any company. This system is perfect for sales teams, market researchers, and anyone needing up-to-date company information.
First, we’ll create a data model that specifies exactly what company information we want to collect. Create a new file called schema.py:
python
from pydantic import BaseModelfrom typing import List, Optionalclass CompanyInfo(BaseModel): # Basic company information name: str = "" # Company name website: str = "" # Official website URL description: str = "" # Brief company description # Detailed information latest_funding: str = "" # Most recent funding information recent_news: List[str] = [] # Latest company news leadership_team: List[str] = [] # Key executives and leaders tech_stack: List[str] = [] # Technologies used by the company
This schema ensures our data is consistently structured and validated.
Next, create company_intel.py to handle the core functionality:
python
from linkup import LinkupClientfrom schema import CompanyInfoclass CompanyIntelligence: def __init__(self, api_key: str): """Initialize the intelligence engine with your API key.""" self.client = LinkupClient(api_key=api_key) def research_company(self, company_name: str) -> CompanyInfo: """ Gather comprehensive information about a company. Args: company_name (str): Name of the company to research Returns: CompanyInfo: Structured company information """ query = f""" Research {company_name} and provide: - Company name, website, and brief description - Most recent funding round or financial announcement - Current leadership team members - Technologies and tools they use - Recent news from the last 3 months Focus on current, verified information. """ # Make the API request with structured output response = self.client.search( query=query, depth="deep", # Get comprehensive results output_type="structured", structured_output_schema=CompanyInfo ) return response
Now let’s make our intelligence engine accessible via HTTP. Create api.py:
python
from fastapi import FastAPI, HTTPExceptionfrom company_intel import CompanyIntelligence# Initialize FastAPI with metadataapp = FastAPI( title="Company Intelligence API", description="Real-time company research and intelligence", version="1.0.0")# Create intelligence engine instanceintel = CompanyIntelligence(api_key="your-linkup-api-key")@app.get("/company/{name}", tags=["Company Research"])async def get_company_info(name: str): """ Retrieve detailed information about a company. Parameters: name (str): Company name to research Returns: CompanyInfo: Structured company information """ try: return intel.research_company(name) except Exception as e: raise HTTPException( status_code=500, detail=f"Error researching company: {str(e)}" )