|
1 | | -##  Python |
| 1 | +## Python FastAPI/Postgres App |
2 | 2 |
|
3 | | -> With FastAPI using Postgres & tsvector. |
| 3 | +**Production-ready, open-source FastAPI application with PostgreSQL and blazing-fast full-text search.** |
4 | 4 |
|
5 | | -Open Source, production ready Python FastAPI/Postgres app. |
| 5 | +--- |
6 | 6 |
|
7 | | -[GitHub](https://github.com/goldlabelapps/python) | |
8 | | -[onr]Render](https://nx-ai.onrender.com) | |
9 | | -[by Goldlabel](https://goldlabel.pro) |
| 7 | +### 🚀 Features |
10 | 8 |
|
11 | 9 | - **Python 3.11+** |
12 | | -- **Postgres** |
13 | | -- **tsvector** - Superfast full-text search (with GIN index) |
| 10 | +- **FastAPI** — Modern, high-performance REST API |
| 11 | +- **PostgreSQL** — Robust relational database |
| 12 | +- **tsvector + GIN** — Superfast full-text search |
| 13 | +- **Uvicorn** — Lightning-fast ASGI server |
| 14 | +- **Pytest** — Comprehensive testing |
14 | 15 |
|
15 | | -```sh |
16 | | -uvicorn app.main:app --reload |
17 | | -``` |
| 16 | +--- |
| 17 | + |
| 18 | +## Project Overview |
| 19 | + |
| 20 | +This project provides a scalable API backend using FastAPI and PostgreSQL, featuring: |
18 | 21 |
|
19 | | -#### Install |
| 22 | +- Automatic full-text search on all text fields (via tsvector) |
| 23 | +- Endpoints for health checks, product management, prompt handling, and prospect management |
| 24 | +- Efficient ingestion and processing of large CSV files |
20 | 25 |
|
21 | | -Create an environment file and add Postgres credentials etc |
| 26 | +--- |
22 | 27 |
|
23 | | -`cp .env.sample .env` |
| 28 | +## Getting Started |
| 29 | + |
| 30 | +### 1. Clone & Setup Environment |
24 | 31 |
|
25 | 32 | ```bash |
| 33 | +git clone <repo-url> |
| 34 | +cd python |
| 35 | +cp .env.sample .env # Add your Postgres credentials and settings |
26 | 36 | python -m venv venv |
27 | 37 | source venv/bin/activate |
28 | 38 | pip install -r requirements.txt |
| 39 | +``` |
| 40 | + |
| 41 | +### 2. Run the App |
| 42 | + |
| 43 | +```bash |
29 | 44 | uvicorn app.main:app --reload |
30 | 45 | ``` |
31 | 46 |
|
32 | | -[localhost](http://localhost:8000) | [onrender](https://nx-ai.onrender.com) |
| 47 | +Visit [localhost:8000](http://localhost:8000) or [onrender](https://nx-ai.onrender.com) |
33 | 48 |
|
| 49 | +--- |
34 | 50 |
|
35 | | -### Full-Text Search (tsvector) |
| 51 | +## API Documentation |
36 | 52 |
|
37 | | -The prospects table includes a `search_vector` column (type: tsvector) that is automatically computed from all text fields on insert. A GIN index is created for this column, enabling fast and scalable full-text search queries. |
| 53 | +FastAPI auto-generates interactive docs: |
38 | 54 |
|
39 | | -**How it works:** |
| 55 | +- [Swagger UI](http://localhost:8000/docs) |
| 56 | +- [ReDoc](http://localhost:8000/redoc) |
40 | 57 |
|
41 | | -- On every insert or update, the `search_vector` is computed from all text columns using PostgreSQL's `to_tsvector('english', ...)`. |
42 | | -- The GIN index (`idx_prospects_search_vector`) allows efficient search queries like: |
| 58 | +--- |
| 59 | + |
| 60 | +## Full-Text Search (tsvector) |
| 61 | + |
| 62 | +The `prospects` table includes a `search_vector` column (type: tsvector) computed from all text fields on insert/update. A GIN index enables fast, scalable full-text search: |
43 | 63 |
|
44 | 64 | ```sql |
45 | 65 | SELECT * FROM prospects WHERE search_vector @@ plainto_tsquery('english', 'search terms'); |
46 | 66 | ``` |
47 | 67 |
|
48 | | -This makes searching across all text fields in the prospects table extremely fast, even for large datasets. |
49 | | -- **FastAPI** — RESTful API framework |
50 | | -- **Uvicorn** — ASGI server |
51 | | -- **Pytest** — testing framework |
52 | | -- **HTTPX / TestClient** |
| 68 | +**How it works:** |
| 69 | +- On every insert/update, `search_vector` is computed using PostgreSQL's `to_tsvector('english', ...)`. |
| 70 | +- The GIN index (`idx_prospects_search_vector`) enables efficient search across large datasets. |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Processing Large CSV Files |
| 75 | + |
| 76 | +The `/prospects/process` endpoint supports robust ingestion of large CSVs (e.g., 1300+ rows, 300KB+), following the same normalization and insertion pattern as `/prospects/seed` but optimized for scale. |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## Directory Structure |
| 81 | + |
| 82 | +``` |
| 83 | +app/ |
| 84 | + main.py # FastAPI entrypoint |
| 85 | + api/ # API endpoints & schemas |
| 86 | + health.py |
| 87 | + root.py |
| 88 | + routes.py |
| 89 | + products/ |
| 90 | + prompts/ |
| 91 | + prospects/ |
| 92 | + resend/ |
| 93 | + utils/ |
| 94 | + static/ # Static assets (e.g., repoicon.png) |
| 95 | + utils/ # Utility scripts |
| 96 | +tests/ # Pytest test suite |
| 97 | +requirements.txt # Python dependencies |
| 98 | +render.yaml # Deployment config (Render.com) |
| 99 | +``` |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## Contributing |
| 104 | + |
| 105 | +Contributions are welcome! Please open issues or submit pull requests. |
| 106 | + |
| 107 | +--- |
53 | 108 |
|
54 | | -#### Docs |
| 109 | +## License |
55 | 110 |
|
56 | | -FastAPI automatically generates interactive documentation: |
| 111 | +This project is licensed under the MIT License. See [LICENSE](LICENSE) for details. |
57 | 112 |
|
58 | | -- Swagger UI: <http://localhost:8000/docs> |
59 | | -- ReDoc: <http://localhost:8000/redoc> |
| 113 | +--- |
60 | 114 |
|
61 | | -### Processing Large CSV Files |
| 115 | +## Contact |
62 | 116 |
|
63 | | -The `/prospects/process` endpoint is designed for robust, scalable ingestion of large CSV files (e.g., 1300+ rows, 300KB+). It follows the same normalization and insertion pattern as `/prospects/seed`, but is optimized for large files: |
| 117 | +For questions or support, open an issue or contact the maintainer. |
64 | 118 |
|
65 | 119 |
|
0 commit comments