Stock Scraper SDK
Reason this release was yanked:
cli command throwing error
Project description
Stock Scraper SDK
A comprehensive Python SDK to scrape, store, and stream live stock prices. This project uses Selenium for scraping Google Finance, FastAPI for REST and WebSocket interfaces, and SQLite for historical data storage.
Folder Structure
stockscraper/
├── README.md # Project documentation
├── pyproject.toml # Project configuration and metadata
├── run.py # Entry point to start the FastAPI server
├── stocks.db # SQLite database containing stock prices history
├── chromedriver-mac-arm64/ # Chromedriver executable (used for Selenium scraping)
├── sdk/ # Core SDK Module
│ ├── api/
│ │ ├── main.py # FastAPI application and WebSocket endpoint setup
│ │ └── routes.py # REST API endpoints (/price/{ticker}, /historical/{ticker})
│ ├── cli/
│ │ └── main.py # CLI wrapper to fetch stock price from the command line
│ ├── streaming/
│ │ ├── manager.py # StockStreamer class to handle live WebSocket price pushing
│ │ └── server.py # Core WebSocket connection lifecycle methods
│ ├── client.py # StockClient acting as the main interface for fetching and saving prices
│ ├── database.py # SQLAlchemy configuration & Session maker
│ ├── models.py # SQLAlchemy Database models (e.g. StockPrice)
│ └── scraper.py # Selenium logic to scrape stock prices directly from Google search
Features
- Live Data Scraping: Uses a headless Selenium browser to bypass simple bot protections and fetch real-time search results from Google.
- REST API: Standard endpoints to query the latest price or get a historical summary of a ticker.
- WebSocket Streaming: Continuous real-time stream of the stock's price to an active WebSocket client.
- Persistent Storage: Uses SQLAlchemy and SQLite to record all requested stock prices into
stocks.db. - Command Line Interface (CLI): Easy checking of stock prices directly from your terminal.
Installation
1. Requirements
Ensure you have Python 3.13+ installed. Since this project uses Selenium, ensure you have Chrome installed on your machine. The chromedriver-mac-arm64 directory contains the chrome driver for Apple Silicon Macs, but the modern Selenium framework should automatically handle driver management.
2. Setup
Clone the repository and install the dependencies. The recommended approach is using a virtual environment:
# Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate # On macOS/Linux
# If using standard pip, install basic requirements
# Note: You may need to install fastapi, uvicorn, selenium, sqlalchemy, and websockets manually if they are not listed in a requirements.txt file.
pip install fastapi uvicorn selenium sqlalchemy websockets
Usage
1. Running the CLI Interface
You can quickly get a stock's current price via the terminal by using the cli module.
python3 -m sdk.cli.main NSE:BEL
2. Running the REST & WebSocket API Server
To start the FastAPI server with hot-reloading:
python3 run.py
This will run the server on http://127.0.0.1:8000.
3. API Endpoints
Once the server is running, the following interfaces are available:
REST API
GET /price/{ticker}: Fetch the immediate current price of a stock (e.g.,http://127.0.0.1:8000/price/NSE:BEL).GET /historical/{ticker}?days=30: Fetch the historically saved prices for a specific stock over a set amount of days.GET /health: Server health-check.
WebSockets
ws://127.0.0.1:8000/ws/{ticker}: Connect to a WebSocket stream that will emit JSON payloads continuously with updated stock information.
npm install -g wscat
Example connecting to the WebSocket using wscat:
wscat -c ws://127.0.0.1:8000/ws/NSE:BEL
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file market_price_tracker-0.1.0.tar.gz.
File metadata
- Download URL: market_price_tracker-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcca799f15da6cc72465c72c8ffbbdc4e4aeba84f5b32c996edfc7b286d10d09
|
|
| MD5 |
69887c060921f62205fe13e45c452aa2
|
|
| BLAKE2b-256 |
428880a7fe63123732934ab475d3ec4511a74826593fe435fc6baeef992b8201
|
File details
Details for the file market_price_tracker-0.1.0-py3-none-any.whl.
File metadata
- Download URL: market_price_tracker-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c01dc83080001f1815ca1f8c3163f14baf35cb7afa6351403e9a9c484e6513cf
|
|
| MD5 |
a4e02c3b6f43e4dab1d20f74b139d2bd
|
|
| BLAKE2b-256 |
3f34be3b8606555fbc8ad66982f8d4e5058066c4eba4a442422218e61862c33b
|