PyGenSearch: Generic Python Search SDK
PyGenSearch is a lightweight, generic search SDK for Python applications. It allows you to easily implement in-memory search functionality for lists of dictionaries, focusing on specific fields.
Features
- Simple to integrate and use.
- Search across multiple specified fields in your data.
- Basic text cleaning and tokenization.
- Configurable searchable fields.
Installation
pip install pygen-search
Usage
Basic Python Example
from pygen_search import PyGenSearch
data = [
{"id": 1, "title": "Learn AI Today", "desc": "Machine Learning is fun.", "category": "tech"},
{"id": 2, "title": "Python Tips", "desc": "Advanced tricks with Python.", "category": "programming"},
]
engine = PyGenSearch(data, searchable_fields=["title", "desc"])
results = engine.search("python")
print(results)
Flask API Example
from flask import Flask, request, jsonify
from pygen_search import PyGenSearch
app = Flask(__name__)
data = [
{"id": 1, "title": "Learn AI Today", "desc": "Machine Learning is fun.", "category": "tech"},
{"id": 2, "title": "Python Tips", "desc": "Advanced tricks with Python.", "category": "programming"},
]
engine = PyGenSearch(data, searchable_fields=["title", "desc"])
@app.route("/search")
def search():
query = request.args.get("q", "")
results = engine.search(query)
return jsonify(results)
if __name__ == "__main__":
app.run(debug=True)
Integrate with HTML/JS Frontend
You can create a simple frontend that calls your Flask API:
HTML/JS Example:
<input id="search" placeholder="Search...">
<ul id="results"></ul>
<script>
document.getElementById('search').addEventListener('input', async function() {
const q = this.value;
const res = await fetch('/search?q=' + encodeURIComponent(q));
const data = await res.json();
document.getElementById('results').innerHTML =
data.map(item => `<li>${item.title}</li>`).join('');
});
</script>
Integrate with React/Next.js
In your React or Next.js app, call your Flask API:
// Example React component
import { useState } from "react";
function Search() {
const [query, setQuery] = useState("");
const [results, setResults] = useState([]);
async function handleSearch(e) {
setQuery(e.target.value);
const res = await fetch(`/search?q=${encodeURIComponent(e.target.value)}`);
const data = await res.json();
setResults(data);
}
return (
<div>
<input value={query} onChange={handleSearch} placeholder="Search..." />
<ul>
{results.map(item => <li key={item.id}>{item.title}</li>)}
</ul>
</div>
);
}
export default Search;
License
MIT License. See LICENSE for details.
Metadata
Release files for pygen-search 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pygen_search-0.1.0.tar.gz | 5.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pygen_search-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.2 kB
Release files / pygen_search-0.1.0.tar.gz
| Download URL | pygen_search-0.1.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13499cb7cb2189841b5a7b43009a4b9626be993fd4b89481ff4c7861f6b1a567
|
|
BLAKE2b-256 checksum How to use checksums |
00c4bd91461301d7df9255cd515cd734370d55f2834fbe9d23ce4c3e8db6dfdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / pygen_search-0.1.0-py3-none-any.whl
| Download URL | pygen_search-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c9024048c1d4d9d15d50a5085e32026370cbbea3e0e6a86edc2256edc3ffd2ec
|
|
BLAKE2b-256 checksum How to use checksums |
d1f677aad8d7a035783616a70d784fe2bf887335b1c4b4d03334fff46f59abdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|