A comprehensive data pipeline for extracting, processing, and visualizing US Treasury financial data. This project features a FastAPI backend deployed on Render, an automated data ingestion pipeline, and an interactive Streamlit dashboard for real-time financial analytics.
The US Treasury Pipeline is a full-stack application designed to ingest Treasury data from official sources, perform data validation and transformation, expose insights through a RESTful API, and visualize metrics via an interactive dashboard. This pipeline serves as a backbone for analyzing Treasury bond yields, auction data, and other critical financial indicators.
Key Objectives:
- Automate Treasury data collection and processing
- Expose cleaned data through a scalable REST API
- Provide real-time financial analytics via interactive dashboard
- Enable programmatic access to Treasury metrics
- Backend API: FastAPI
- Data Extraction: US treasury API
- API Hosting: Render
- Frontend Dashboard: Streamlit
- Languages: Python
- Visualization: Streamlit
- Infrastructure: Docker
- Data Storage: Postgres Database hosted on aiven
US-Treasury-Pipeline/
βββ Api/ # FastAPI application & endpoints
β βββ main.py # FastAPI application entry point
β βββ models/ # Data models & schemas
βββ Data/ # Raw and processed data storage
β βββ db_conn #Connection to database
β βββ data.py # data extraction
| βββ models.py # Data models for API endpoint
βββ Logs/ # Pipeline execution logs
β βββ [Execution records and error tracking]
βββ monitor/
| βββ monitor_db.py # Make connection to database, create table for monitoring
| βββ monitor.py # Make a request to API endpoint, check fir status and append staus to db
βββ dashboard.py # Streamlit frontend application
βββ dag.py # Dag file
βββ requirements.txt # Python dependencies
βββ Dockerfile # Container configuration
βββ .gitignore # Git ignore rules
βββ .dockerignore # Docker ignore rules
βββ README.md # Project documentation
- Fetches Treasury data from public sources (US Department of Treasury APIs)
- Handles authentication, rate limiting, and error handling
- Validates data quality and performs deduplication
- Stores processed data in
Data/folder
- RESTful API endpoints serving Treasury data
- Data models with Pydantic validation
- CORS-enabled for cross-origin requests
- Deployed on Render cloud platform
- Handles authentication and request validation
- Consumes data from FastAPI backend via HTTP requests
- Interactive web interface for exploring Treasury metrics
- Real-time data visualization and trend analysis
- Responsive UI with filters and date range selectors
- Persistent storage of raw and processed datasets into the database
- Batch data uploads(200 records per insertion) for 4861 records
- Organized by data type and time period
STREAMLIT DASHBOARD URL :https://us-treasury-pipeline-rijzjnbzowvw8ydra7f5uq.streamlit.app/
- Python 3.9+
- Docker & Docker Compose
- Git
- Render account (for API deployment)
-
Clone the Repository
git clone https://github.com/Human-Gechi/US-Treasury-Pipeline.git cd US-Treasury-Pipeline -
Install Dependencies
pip install -r requirements.txt
-
Configure Environment Variables Create a
.envfile:# API Configuration API_KEY= *** # DATABASE CREDENTIALS DATABASE_URL = *****
-
Run Locally with Docker
docker-compose up -d
cd Api
uvicorn main:app --reload --host 0.0.0.0 --port 8000API will be available at: http://localhost:8000
API Docs (Swagger UI): http://localhost:8000/docs
In a separate terminal:
streamlit run dashboard.pyDashboard will be available at: http://localhost:8501
FastAPI is already deployed on Render:
- API Endpoint:
https://your-app.onrender.com - Health Check:
https://your-app.onrender.com/health - API Documentation:
https://your-app.onrender.com/docs
The Streamlit dashboard automatically connects to the Render-hosted API in production.
| Method | Endpoint | Description |
|---|---|---|
GET |
/records/health |
Health check |
GET |
/records |
Fetch First 50 Treasury data for avergae_securities |
GET |
/records/record_count |
Fetch total records at the endpoint |
GET |
/records/latest |
Fetch latest record |
GET |
/records/type |
Fetch records by type |
GET |
/records/by-date |
Fetch records by date |
GET |
get_records_by_security_type |
Filter records by security type |
GET |
get_records_by_security_type_and_date |
Fetch records by securities_type and date |
- Data Extraction -> Treasury APIs fetch latest financial metrics
- Transformation -> Cleaning, aggregation, and enrichment
- Storage -> Processed data persisted to database
- API Exposure -> FastAPI serves data via REST endpoints
- Visualization -> Streamlit dashboard consumes API data and displays insights
- Data Ochestration -> Airflow: Fetches data monthly from the endpoint
- Real-time Metrics Dashboard -> Current average securities yields and rates
- Historical Trend Analysis -> Graph depicting securities trends overtime
- Record count -> Total count, individual security type count
- Latest Record
- Check API is running: Check render service if you provided the accurate credentials
- Clear browser cache and restart Streamlit
- Ensure data files exist in
Data/folder - Verify API credentials in environment variables
- Check API logs for data fetch errors
# Rebuild containers
docker-compose build --no-cache
# Clear volumes
docker-compose down -v
# Restart all services
docker-compose up -d- Store API keys in environment variables (never hardcode)
- Use Render's environment variable management for production secrets
- Enable CORS only for trusted domains
The pipeline processes Treasury metrics including:
- record_date
- record_year (Generated at runtime from record_date)
- security_type_desc (Marketable, Non-Marketable, Interest-bearin debt) -avg_interest_rate_amt (%avg_interest_rate)
- GitHub repository linked to Render
- Docker image building enabled
-
Create Render Service
- Go to https://dashboard.render.com
- Click "New" -> "Web Service"
- Connect GitHub repository
- Set Build Command:
pip install -r requirements.txt - Set Start Command:
uvicorn Api.main:app --host 0.0.0.0 --port $PORT
-
Configure Environment Variables
- Add all variables from
.envin Render dashboard
- Add all variables from
-
Deploy
- Click "Deploy"
- Monitor logs in Render dashboard
- API will be live at provided URL
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/YourFeature) - Commit changes (
git commit -m 'Add YourFeature') - Push to the branch (
git push origin feature/YourFeature) - Open a Pull Request
- API Response Time: 200 - 500 ms
- Dashboard Load Time: <= 50 seconds
- Data Refresh Frequency: Every month
- Data Accuracy: 95%
This project is open source and available under the MIT License.
Ogechukwu Abimbola OkolΡ
Building scalable data pipelines and analytics systems.
- Focus: Data Engineering,Anaytics, ML
- LinkedIn: LinkedIn
- GitHub: @Human-Gechi