This is a Flask-based Financial Analysis API that allows users to:
- Extract stock ticker symbols from natural language queries.
- Fetch financial data for a stock using Yahoo Finance.
- Analyze stock data using AI-driven financial analysis.
/flask_financial_api
βββ /app
β βββ /api
β β βββ __init__.py
β β βββ routes.py
β βββ /models
β β βββ __init__.py
β β βββ stock.py
β βββ /services
β β βββ __init__.py
β β βββ symbol_extractor.py
β β βββ data_fetcher.py
β β βββ stock_analysis.py
β βββ /utils
β β βββ __init__.py
β β βββ logger.py
β βββ /config
β β βββ __init__.py
β β βββ settings.py
β βββ /middleware
β β βββ __init__.py
β β βββ error_handler.py
β βββ __init__.py
β βββ extensions.py
βββ /migrations
βββ /tests
β βββ __init__.py
β βββ test_routes.py
βββ /instance
βββ .env
βββ requirements.txt
βββ gunicorn_config.py
βββ wsgi.py
βββ README.md
- Python 3.12+
- Anaconda (if using Conda environments)
git clone https://github.com/yourusername/flask_financial_api.git
cd flask_financial_apiconda create -n financial_api_env python=3.12
conda activate financial_api_envOr using venv:
python -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windowspip install -r requirements.txtflask db init
flask db migrate -m "Initial migration"
flask db upgradeflask runBy default, the API runs at: http://127.0.0.1:5000
For public access:
flask run --host=0.0.0.0 --port=5000POST /api/extract-symbol
{
"query": "symbol for microsoft"
}{
"symbol":"The stock ticker symbol for Microsoft is:\n\nMSFT"
}POST /api/fetch-financials
{
"ticker": "AAPL"
}{
"file":"MSFT.json",
"message":"Financial data successfully saved at MSFT.json"
}POST /api/analyze-stock
{
"file_path": "AAPL.json",
"query": "Analyze this stock"
}{
"analysis": "The stock shows strong profitability....... I would recommend that the trader hold the stock..."
}pytest tests/Expected output:
================================================= 3 passed in 13.74s ==================================================
pip install waitress
waitress-serve --listen=0.0.0.0:5000 wsgi:app|
This project is open-source and available under the MIT License.
- Fork the repository
- Create a new branch (
git checkout -b feature-branch) - Commit your changes (
git commit -m 'Add new feature') - Push to the branch (
git push origin feature-branch) - Create a pull request π