AI-powered company context extraction using Gemini with Google Search grounding.
┌─────────────────────────────────────────────────────────────────┐
│ OpenContext │
├─────────────────────────────────────────────────────────────────┤
│ CLI (cli.py) │ API (api.py) │
│ - opencontext analyze │ - POST /api/v1/analyze (sync) │
│ - opencontext config │ - POST /api/v1/jobs (async) │
│ - opencontext check │ - GET /api/v1/jobs/{id} │
├─────────────────────────────────────────────────────────────────┤
│ opencontext/ │
│ - models.py Pydantic models (CompanyContext, etc.) │
│ - opencontext.py Core analysis logic │
│ - prompts/ Prompt text files │
├─────────────────────────────────────────────────────────────────┤
│ shared/ │
│ - gemini_client.py Unified Gemini client │
│ - prompt_loader.py Load prompts from files │
│ - constants.py GEMINI_MODEL config │
└─────────────────────────────────────────────────────────────────┘
opencontext/
├── cli.py # CLI entry point
├── api.py # FastAPI REST API
├── opencontext/ # Main package
│ ├── __init__.py
│ ├── models.py # Pydantic models
│ ├── opencontext.py # Core analysis logic
│ └── prompts/
│ └── opencontext.txt # Analysis prompt
├── shared/ # Shared components
│ ├── __init__.py
│ ├── constants.py # GEMINI_MODEL
│ ├── gemini_client.py # Unified Gemini client
│ └── prompt_loader.py # Prompt file loader
├── pyproject.toml # Package config
├── requirements.txt # Dependencies
└── README.md
company_name,company_url,industry,descriptionproducts,target_audience,competitors,tonepain_points,value_propositions,use_cases,content_themesvoice_persona(VoicePersona)visual_identity(VisualIdentity)authors(List[AuthorInfo])
icp_profile,voice_stylelanguage_style(formality, complexity, sentence_length, perspective)do_list,dont_list,example_phrases,opening_styles
brand_colors,secondary_colorsvisual_style,design_elements,typography_style,moodimage_style_prompt(for AI image generation)blog_image_examples(List[BlogImageExample])avoid_in_images
name,title,bioimage_url,linkedin_url,twitter_url
- Shared GeminiClient: Unified client with URL Context + Google Search grounding
- Prompt Files: Prompts in text files for easy iteration without code changes
- Pydantic Models: Type-safe schemas with validation
- Dual Interface: CLI for local use, FastAPI for integration
- Fallback Mode: Basic detection from URL if no API key or AI fails
- Full Parity: Schema matches openblog/stage 1 for seamless integration
GEMINI_API_KEY=your-gemini-api-key
GEMINI_MODEL=gemini-2.0-flash # optional override
# Analyze company
opencontext analyze https://example.com
# Verbose output
opencontext analyze https://example.com -v
# Configure API key
opencontext config# Start server
uvicorn api:app --reload --port 8000
# Synchronous analysis
curl -X POST http://localhost:8000/api/v1/analyze \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}'
# Async job
curl -X POST http://localhost:8000/api/v1/jobs \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}'
# Check job status
curl http://localhost:8000/api/v1/jobs/{job_id}from opencontext import get_company_context
context, ai_called = await get_company_context("https://example.com")
print(context.company_name)
print(context.visual_identity.brand_colors)This package provides Stage 1 context for the openblog pipeline:
# In openblog Stage 1
from opencontext import get_company_context, CompanyContext
context, _ = await get_company_context(company_url)
# context.visual_identity.image_style_prompt → Stage 2 image generation
# context.authors → Article author assignment
# context.voice_persona → Content writing guide| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Health check |
| GET | /health |
Health check (alias) |
| POST | /api/v1/analyze |
Analyze company (sync, blocking) |
| POST | /api/v1/jobs |
Start analysis job (async) |
| GET | /api/v1/jobs |
List all jobs |
| GET | /api/v1/jobs/{id} |
Get job status/result |
| DELETE | /api/v1/jobs/{id} |
Delete job |
google-genai>=1.0- Gemini API clientpydantic>=2.0- Data validationpython-dotenv>=1.0- Environment variablesclick>=8.0- CLI frameworkrich>=13.0- Beautiful terminal outputfastapi>=0.109- REST API frameworkuvicorn>=0.27- ASGI server