A simple and extensible search SDK for Python applications.
Project description
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.
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 pygen_search-0.1.0.tar.gz.
File metadata
- Download URL: pygen_search-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13499cb7cb2189841b5a7b43009a4b9626be993fd4b89481ff4c7861f6b1a567
|
|
| MD5 |
2ca4c9b7a25acea43e8a1022ba341d9f
|
|
| BLAKE2b-256 |
00c4bd91461301d7df9255cd515cd734370d55f2834fbe9d23ce4c3e8db6dfdc
|
File details
Details for the file pygen_search-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pygen_search-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9024048c1d4d9d15d50a5085e32026370cbbea3e0e6a86edc2256edc3ffd2ec
|
|
| MD5 |
01777ff2981c7a6e96572a18d732a314
|
|
| BLAKE2b-256 |
d1f677aad8d7a035783616a70d784fe2bf887335b1c4b4d03334fff46f59abdf
|