This project demonstrates how to integrate Redis, HubSpot, and FastAPI to build a scalable backend solution. Redis is used here for managing OAuth credentials and session data, while HubSpot’s API is used to manage CRM data. FastAPI is the web framework that provides fast, asynchronous APIs.
- OAuth Credential Management: Redis is used to securely manage OAuth credentials and sessions.
- HubSpot Integration: Fetch and manage CRM and marketing data using HubSpot’s API.
- FastAPI: A fast web framework for creating asynchronous APIs.
- Caching: Redis is also used for caching data to improve the performance of the system.
- FastAPI: A modern web framework for building high-performance APIs with Python.
- Redis: In-memory data store for caching, OAuth credential management, and session management.
- HubSpot API: CRM and marketing automation integration via HubSpot's REST API.
Before you begin, ensure you have the following installed:
- Python 3.7+
- Redis (for local development, or a Redis cloud service)
- HubSpot API key (you will need to generate one from HubSpot’s developer portal)
-
Clone the Repository
git clone https://github.com/likhithkp/hubspot-fastapi-integration cd hubspot-fastapi-integration
-
Create a Virtual Environment
python3 -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install Dependencies
pip install -r requirements.txt
-
Set Up Redis
Ensure Redis is running locally or configure it to use a cloud Redis service. If you're running Redis locally, you can start it with:
redis-server
-
Configure HubSpot API
Set up your HubSpot API key in the
.env
file or directly in your environment variables:HUBSPOT_API_KEY=your-hubspot-api-key
-
Run the FastAPI Application
uvicorn app.main:app --reload
This will start the FastAPI server locally on
http://127.0.0.1:8000
.
- GET /integrations/hubspot/authorize: Create oauth state and generate authorized URL.
- GET /integrations/hubspot/oauth2callback: Callback function which validates the credentials.
- GET /integrations/hubspot/credentials: Fetch credentials from redis and send to frontend.
- GET /integrations/hubspot/get_hubspot_items: Fetches required data (any data) from HubSpot.
For detailed API documentation, visit http://127.0.0.1:8000/docs
after running the server.
- Redis is used to store and manage OAuth tokens securely for each user session.
- When a user logs in, the OAuth credentials are stored in Redis for quick access.
Contributions are welcomed! If you'd like to contribute to the project, follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature-branch
) - Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature-branch
) - Open a pull request
This project is licensed under the MIT License - see the LICENSE file for details.