A high-performance FastAPI boilerplate for creating Node APIs in workflows, with Gemini, Redis, and S3 integration.
Project description
PyFlow AI Stack
PyFlow AI Stack is a high-performance Python library designed for building robust Node APIs and AI Workers within workflow automation systems (like Dify, LangChain, or custom microservices).
It provides a unified, production-ready interface for interacting with Google Gemini AI, Redis Caching, and S3-compatible Object Storage, featuring built-in concurrency management, health diagnostics, and structured configuration.
✨ Key Features
- Unified AI Interface: Seamlessly interact with Google Gemini models with managed concurrency.
- Asynchronous Caching: Optimized Redis service for high-throughput data persistence and retrieval.
- Scalable Storage: Multi-cloud support for AWS S3, MinIO, and other S3-compatible providers.
- Production Ready: Built-in logging, error handling, and health check diagnostics.
- Workflow Native: Specifically architected to act as a backend for workflow nodes and microservice workers.
🛠️ Installation
You can install the library directly from the repository:
pip install git+https://github.com/tranthethang/pyflow-ai-stack.git
Or if you are developing locally:
git clone https://github.com/tranthethang/pyflow-ai-stack.git
cd pyflow-ai-stack
pip install .
🚀 Quick Start
1. Configuration
The library uses a centralized Settings class powered by Pydantic. You can configure it via environment variables or a .env file.
from pyflow_ai_stack import Settings
# Load settings from environment/defaults
settings = Settings()
# Or load from a specific .env file
settings = Settings.load(env_file=".env")
2. Using Gemini AI
Handle complex LLM tasks with the GeminiService.
import asyncio
from pyflow_ai_stack import GeminiService, Settings
async def main():
settings = Settings()
service = GeminiService(settings.gemini)
# Generate simple text
response = await service.generate_content("Explain quantum computing in 50 words.")
print(f"Gemini: {response}")
# Generate with system instructions
response = await service.generate_content(
prompt="Tell me a joke.",
system_instruction="You are a sarcastic comedian."
)
print(f"Sarcastic Gemini: {response}")
asyncio.run(main())
3. Asynchronous Caching with Redis
import asyncio
from pyflow_ai_stack import RedisService, Settings
async def cache_example():
settings = Settings()
redis = RedisService(settings.redis)
# Set a value with 60s expiration
await redis.set("user_session_123", '{"name": "John"}', expire=60)
# Get a value
data = await redis.get("user_session_123")
print(f"Cached Data: {data}")
asyncio.run(cache_example())
4. S3 Object Storage
import asyncio
from pyflow_ai_stack import S3Service, Settings
async def s3_example():
settings = Settings()
s3 = S3Service(settings.s3)
# Upload content
uri = await s3.upload_file(
content="Hello S3!",
s3_key="notes/hello.txt",
content_type="text/plain"
)
print(f"Uploaded to: {uri}")
# Download content
content = await s3.get_file("notes/hello.txt")
print(f"Downloaded: {content}")
asyncio.run(s3_example())
📂 Library Components
| Component | Description |
|---|---|
GeminiService |
Handles interactions with Google Generative AI (Gemini). |
RedisService |
Asynchronous Redis client for caching and state management. |
S3Service |
Asynchronous S3 client for object storage (AWS, MinIO, etc.). |
HealthService |
Aggregates health status from all connected services. |
Settings |
Pydantic-based configuration management. |
🏥 Health Diagnostics
Ensure all your services are correctly configured and reachable:
import asyncio
from pyflow_ai_stack import HealthService, Settings, GeminiService, RedisService, S3Service
async def check_system():
settings = Settings()
# Pass service instances to HealthService
health = HealthService(
gemini=GeminiService(settings.gemini),
redis=RedisService(settings.redis),
s3=S3Service(settings.s3)
)
status = await health.check_health(depends=1)
print(f"System Status: {status}")
asyncio.run(check_system())
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
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 pyflow_ai_stack-1.0.0.tar.gz.
File metadata
- Download URL: pyflow_ai_stack-1.0.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5689e7243083979e7a3fe67d1aa58a9ab35a65cc2ef4d32fd26cf68f3311e1b0
|
|
| MD5 |
90c24ae679bf447dfa7c4f2705d5854b
|
|
| BLAKE2b-256 |
12e90e6a0710a5755c77195503ae4e9c8ea177be0cfe38c71a31840485dd07db
|
File details
Details for the file pyflow_ai_stack-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyflow_ai_stack-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2fcf336fdec9deee165c86ecdd3dea33d5501a70099ac44b62f25b9146c18ad
|
|
| MD5 |
202a5787b2c9194758bbc6b8d1b0cd55
|
|
| BLAKE2b-256 |
aeb41fda2cc32efd37c585f73ccce78e11d41319da4acbe53a5a1b039193cda0
|