fastapi-lite-admin 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. fastapi_lite_admin-0.1.2/LICENSE +21 -0
  2. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/PKG-INFO +3 -1
  3. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/core/crud.py +34 -38
  4. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/routers/admin.py +14 -12
  5. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/ui/views.py +53 -46
  6. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_lite_admin.egg-info/PKG-INFO +3 -1
  7. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_lite_admin.egg-info/SOURCES.txt +1 -0
  8. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/pyproject.toml +1 -1
  9. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/README.md +0 -0
  10. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/__init__.py +0 -0
  11. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/core/config.py +0 -0
  12. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/core/registry.py +0 -0
  13. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/core/schema.py +0 -0
  14. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/dependencies/db.py +0 -0
  15. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/integrations/sqlalchemy.py +0 -0
  16. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/main.py +0 -0
  17. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/ui/templates/dashboard.html +0 -0
  18. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/ui/templates/layout.html +0 -0
  19. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/ui/templates/model_detail.html +0 -0
  20. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/ui/templates/model_form.html +0 -0
  21. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_admin_lite/ui/templates/model_list.html +0 -0
  22. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_lite_admin.egg-info/dependency_links.txt +0 -0
  23. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_lite_admin.egg-info/requires.txt +0 -0
  24. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/fastapi_lite_admin.egg-info/top_level.txt +0 -0
  25. {fastapi_lite_admin-0.1.0 → fastapi_lite_admin-0.1.2}/setup.cfg +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rishav Sharma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi-lite-admin
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: A lightweight, pluggable admin panel for FastAPI
5
5
  License: MIT
6
6
  Requires-Python: >=3.9
7
7
  Description-Content-Type: text/markdown
8
+ License-File: LICENSE
8
9
  Requires-Dist: fastapi>=0.100.0
9
10
  Requires-Dist: sqlalchemy>=2.0.0
10
11
  Requires-Dist: pydantic>=2.0.0
@@ -14,6 +15,7 @@ Provides-Extra: dev
14
15
  Requires-Dist: pytest; extra == "dev"
15
16
  Requires-Dist: httpx; extra == "dev"
16
17
  Requires-Dist: uvicorn; extra == "dev"
18
+ Dynamic: license-file
17
19
 
18
20
  # FastAPI Lite Admin
19
21
 
@@ -1,6 +1,7 @@
1
1
  from typing import Any, List, Optional, Type
2
- from sqlalchemy.orm import Session
3
- from sqlalchemy import Boolean, Integer, Float
2
+ from sqlalchemy.ext.asyncio import AsyncSession
3
+ from sqlalchemy import select, func, Boolean, Integer, Float
4
+
4
5
 
5
6
  class CRUDEngine:
6
7
  def __init__(self, model: Type[Any]):
@@ -39,26 +40,33 @@ class CRUDEngine:
39
40
 
40
41
  return prepared
41
42
 
42
- def count(self, db: Session, search: Optional[str] = None) -> int:
43
- query = db.query(self.model)
44
- # TODO: Implement search filtering in count
45
- return query.count()
43
+ async def count(self, db: AsyncSession, search: Optional[str] = None) -> int:
44
+ query = select(func.count()).select_from(self.model)
45
+ if search:
46
+ for column in self.model.__table__.columns:
47
+ if hasattr(column.type, "python_type") and column.type.python_type == str:
48
+ query = query.filter(column.contains(search))
49
+ break
50
+ result = await db.execute(query)
51
+ return result.scalar()
46
52
 
47
- def list(
53
+ async def list(
48
54
  self,
49
- db: Session,
55
+ db: AsyncSession,
50
56
  skip: int = 0,
51
57
  limit: int = 100,
52
58
  search: Optional[str] = None,
53
59
  order_by: Optional[str] = None,
54
60
  order_dir: str = "asc"
55
61
  ) -> List[Any]:
56
- query = db.query(self.model)
62
+ query = select(self.model).offset(skip).limit(limit)
57
63
 
58
64
  # Apply Search
59
65
  if search:
60
- # TODO: Implement generic search logic
61
- pass
66
+ for column in self.model.__table__.columns:
67
+ if hasattr(column.type, "python_type") and column.type.python_type == str:
68
+ query = query.filter(column.contains(search))
69
+ break
62
70
 
63
71
  # Apply Sorting
64
72
  if order_by and hasattr(self.model, order_by):
@@ -68,48 +76,36 @@ class CRUDEngine:
68
76
  else:
69
77
  query = query.order_by(column.asc())
70
78
 
71
- return query.offset(skip).limit(limit).all()
72
-
73
- def _cast_id(self, id: Any) -> Any:
74
- """
75
- Cast ID to the correct type based on the model's primary key.
76
- """
77
- col = self.model.__table__.primary_key.columns[0]
78
- if isinstance(col.type, Integer):
79
- try:
80
- return int(id)
81
- except (ValueError, TypeError):
82
- return id
83
- return id
79
+ result = await db.execute(query)
80
+ return result.scalars().all()
84
81
 
85
- def get(self, db: Session, id: Any) -> Optional[Any]:
86
- casted_id = self._cast_id(id)
87
- return db.query(self.model).filter(self.model.id == casted_id).first()
82
+ async def get(self, db: AsyncSession, id: Any) -> Optional[Any]:
83
+ return await db.get(self.model, id)
88
84
 
89
- def create(self, db: Session, data: dict) -> Any:
85
+ async def create(self, db: AsyncSession, data: dict) -> Any:
90
86
  prepared_data = self._prepare_data(data)
91
87
  obj = self.model(**prepared_data)
92
88
  db.add(obj)
93
- db.commit()
94
- db.refresh(obj)
89
+ await db.commit()
90
+ await db.refresh(obj)
95
91
  return obj
96
92
 
97
- def update(self, db: Session, id: Any, data: dict) -> Optional[Any]:
98
- obj = self.get(db, id)
93
+ async def update(self, db: AsyncSession, id: Any, data: dict) -> Optional[Any]:
94
+ obj = await self.get(db, id)
99
95
  if not obj:
100
96
  return None
101
97
 
102
98
  prepared_data = self._prepare_data(data)
103
99
  for key, value in prepared_data.items():
104
100
  setattr(obj, key, value)
105
- db.commit()
106
- db.refresh(obj)
101
+ await db.commit()
102
+ await db.refresh(obj)
107
103
  return obj
108
104
 
109
- def delete(self, db: Session, id: Any) -> bool:
110
- obj = self.get(db, id)
105
+ async def delete(self, db: AsyncSession, id: Any) -> bool:
106
+ obj = await self.get(db, id)
111
107
  if not obj:
112
108
  return False
113
- db.delete(obj)
114
- db.commit()
109
+ await db.delete(obj)
110
+ await db.commit()
115
111
  return True
@@ -1,6 +1,6 @@
1
1
  from typing import Any, Dict, List
2
2
  from fastapi import APIRouter, Depends, HTTPException, Query
3
- from sqlalchemy.orm import Session
3
+ from sqlalchemy.ext.asyncio import AsyncSession
4
4
  from ..core.schema import generate_admin_schema
5
5
  from ..core.crud import CRUDEngine
6
6
 
@@ -28,44 +28,46 @@ def create_admin_router(admin: Any) -> APIRouter:
28
28
  search: str = None,
29
29
  order_by: str = None,
30
30
  order_dir: str = "asc",
31
- db: Session = Depends(db_dep)
31
+ db: AsyncSession = Depends(db_dep)
32
32
  ):
33
- records = crud_engine.list(
33
+ records = await crud_engine.list(
34
34
  db, skip=skip, limit=limit, search=search,
35
35
  order_by=order_by, order_dir=order_dir
36
36
  )
37
- total = crud_engine.count(db, search=search)
37
+ total = await crud_engine.count(db, search=search)
38
38
  return {"data": records, "total": total}
39
39
 
40
40
  @router.get(f"/{model_name}/{{id}}", name=f"admin_get_{model_name}")
41
- async def get_record(id: Any, db: Session = Depends(db_dep)):
42
- record = crud_engine.get(db, id)
41
+ async def get_record(id: Any, db: AsyncSession = Depends(db_dep)):
42
+ record = await crud_engine.get(db, id)
43
43
  if not record:
44
44
  raise HTTPException(status_code=404, detail="Record not found")
45
45
  return record
46
46
 
47
47
  @router.post(f"/{model_name}", name=f"admin_create_{model_name}")
48
- async def create_record(data: Dict[str, Any], db: Session = Depends(db_dep)):
48
+ async def create_record(data: Dict[str, Any], db: AsyncSession = Depends(db_dep)):
49
+ # Remove readonly fields from incoming data
49
50
  readonly = reg.config.get("readonly_fields", [])
50
51
  for field in readonly:
51
52
  if field in data:
52
53
  del data[field]
53
- return crud_engine.create(db, data)
54
+ return await crud_engine.create(db, data)
54
55
 
55
56
  @router.put(f"/{model_name}/{{id}}", name=f"admin_update_{model_name}")
56
- async def update_record(id: Any, data: Dict[str, Any], db: Session = Depends(db_dep)):
57
+ async def update_record(id: Any, data: Dict[str, Any], db: AsyncSession = Depends(db_dep)):
58
+ # Remove readonly fields from incoming data
57
59
  readonly = reg.config.get("readonly_fields", [])
58
60
  for field in readonly:
59
61
  if field in data:
60
62
  del data[field]
61
- record = crud_engine.update(db, id, data)
63
+ record = await crud_engine.update(db, id, data)
62
64
  if not record:
63
65
  raise HTTPException(status_code=404, detail="Record not found")
64
66
  return record
65
67
 
66
68
  @router.delete(f"/{model_name}/{{id}}", name=f"admin_delete_{model_name}")
67
- async def delete_record(id: Any, db: Session = Depends(db_dep)):
68
- success = crud_engine.delete(db, id)
69
+ async def delete_record(id: Any, db: AsyncSession = Depends(db_dep)):
70
+ success = await crud_engine.delete(db, id)
69
71
  if not success:
70
72
  raise HTTPException(status_code=404, detail="Record not found")
71
73
  return {"success": True}
@@ -14,31 +14,38 @@ def create_ui_router(admin: Any) -> APIRouter:
14
14
  @router.get("/", response_class=HTMLResponse)
15
15
  async def dashboard(request: Request):
16
16
  from datetime import datetime, timedelta
17
+ from sqlalchemy import select, func
17
18
  models = admin.registry.get_models()
18
- model_names = list(models.keys())
19
19
 
20
20
  # Collect real counts for each model
21
21
  stats = []
22
22
  for name, reg in models.items():
23
- # Skip if user has specified a subset of models for the dashboard
24
23
  if admin.dashboard_models and name not in admin.dashboard_models:
25
24
  continue
26
25
 
27
26
  db_gen = reg.get_db()
28
- db = next(db_gen)
27
+ # Handle both async and sync generators for maximum compatibility
28
+ if hasattr(db_gen, "__anext__"):
29
+ db = await db_gen.__anext__()
30
+ else:
31
+ db = next(db_gen)
32
+
29
33
  try:
30
34
  # 1. Get Total Count
31
- total_count = db.query(reg.model).count()
35
+ total_query = select(func.count()).select_from(reg.model)
36
+ total_result = await db.execute(total_query)
37
+ total_count = total_result.scalar()
32
38
 
33
- # 2. Get 24h Count if date_field is set
39
+ # 2. Get 24h Count
34
40
  recent_count = None
35
41
  date_field = reg.config.get("date_field")
36
-
37
42
  if date_field and hasattr(reg.model, date_field):
38
43
  yesterday = datetime.now() - timedelta(hours=24)
39
- recent_count = db.query(reg.model).filter(
44
+ recent_query = select(func.count()).select_from(reg.model).filter(
40
45
  getattr(reg.model, date_field) >= yesterday
41
- ).count()
46
+ )
47
+ recent_result = await db.execute(recent_query)
48
+ recent_count = recent_result.scalar()
42
49
 
43
50
  stats.append({
44
51
  "name": reg.config.get("display_name") or name.capitalize(),
@@ -48,68 +55,68 @@ def create_ui_router(admin: Any) -> APIRouter:
48
55
  "has_date_field": bool(date_field)
49
56
  })
50
57
  finally:
51
- # Handle generators properly
52
- try:
53
- next(db_gen)
54
- except StopIteration:
55
- pass
56
-
57
- # Fetch Logs
58
- logs = []
58
+ if hasattr(db_gen, "aclose"):
59
+ await db_gen.aclose()
60
+ elif hasattr(db_gen, "close"):
61
+ db_gen.close()
62
+
63
+ # Handle logs
64
+ recent_logs = []
59
65
  if admin.get_logs:
60
66
  try:
61
- logs = admin.get_logs()
67
+ if asyncio.iscoroutinefunction(admin.get_logs):
68
+ recent_logs = await admin.get_logs()
69
+ else:
70
+ recent_logs = admin.get_logs()
62
71
  except Exception as e:
63
72
  print(f"Error fetching logs: {e}")
64
73
 
65
74
  return templates.TemplateResponse(
66
75
  request=request,
67
- name=admin.dashboard_template or "dashboard.html",
68
- context={
69
- "models": model_names,
70
- "stats": stats,
71
- "admin_title": admin.title,
72
- "logs": logs,
73
- "logs_config": admin.logs_config
74
- }
76
+ name="dashboard.html",
77
+ context={"stats": stats, "recent_logs": recent_logs, "models": list(models.keys())}
75
78
  )
76
79
 
77
80
  @router.get("/{model_name}", response_class=HTMLResponse)
78
81
  async def model_list(request: Request, model_name: str):
79
82
  from datetime import datetime, timedelta
83
+ from sqlalchemy import select, func
80
84
  reg = admin.registry.get_model(model_name)
81
85
  if not reg:
82
86
  raise HTTPException(status_code=404, detail="Model not found")
83
87
 
84
88
  models = list(admin.registry.get_models().keys())
85
89
 
86
- # Calculate 24h stats for this specific model
90
+ # Calculate stats for this specific model
87
91
  recent_count = None
92
+ attention_count = None
88
93
  date_field = reg.config.get("date_field")
94
+ attn_filter = reg.config.get("attention_filter")
89
95
 
90
- if date_field and hasattr(reg.model, date_field):
91
- db_gen = reg.get_db()
96
+ db_gen = reg.get_db()
97
+ if hasattr(db_gen, "__anext__"):
98
+ db = await db_gen.__anext__()
99
+ else:
92
100
  db = next(db_gen)
93
- try:
101
+
102
+ try:
103
+ if date_field and hasattr(reg.model, date_field):
94
104
  yesterday = datetime.now() - timedelta(hours=24)
95
- recent_count = db.query(reg.model).filter(
105
+ recent_query = select(func.count()).select_from(reg.model).filter(
96
106
  getattr(reg.model, date_field) >= yesterday
97
- ).count()
98
- finally:
99
- try: next(db_gen)
100
- except StopIteration: pass
101
-
102
- # Calculate Attention count
103
- attention_count = None
104
- attn_filter = reg.config.get("attention_filter")
105
- if attn_filter is not None:
106
- db_gen = reg.get_db()
107
- db = next(db_gen)
108
- try:
109
- attention_count = db.query(reg.model).filter(attn_filter).count()
110
- finally:
111
- try: next(db_gen)
112
- except StopIteration: pass
107
+ )
108
+ recent_result = await db.execute(recent_query)
109
+ recent_count = recent_result.scalar()
110
+
111
+ if attn_filter is not None:
112
+ attn_query = select(func.count()).select_from(reg.model).filter(attn_filter)
113
+ attn_result = await db.execute(attn_query)
114
+ attention_count = attn_result.scalar()
115
+ finally:
116
+ if hasattr(db_gen, "aclose"):
117
+ await db_gen.aclose()
118
+ elif hasattr(db_gen, "close"):
119
+ db_gen.close()
113
120
 
114
121
  return templates.TemplateResponse(
115
122
  request=request,
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastapi-lite-admin
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: A lightweight, pluggable admin panel for FastAPI
5
5
  License: MIT
6
6
  Requires-Python: >=3.9
7
7
  Description-Content-Type: text/markdown
8
+ License-File: LICENSE
8
9
  Requires-Dist: fastapi>=0.100.0
9
10
  Requires-Dist: sqlalchemy>=2.0.0
10
11
  Requires-Dist: pydantic>=2.0.0
@@ -14,6 +15,7 @@ Provides-Extra: dev
14
15
  Requires-Dist: pytest; extra == "dev"
15
16
  Requires-Dist: httpx; extra == "dev"
16
17
  Requires-Dist: uvicorn; extra == "dev"
18
+ Dynamic: license-file
17
19
 
18
20
  # FastAPI Lite Admin
19
21
 
@@ -1,3 +1,4 @@
1
+ LICENSE
1
2
  README.md
2
3
  pyproject.toml
3
4
  fastapi_admin_lite/__init__.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fastapi-lite-admin"
7
- version = "0.1.0"
7
+ version = "0.1.2"
8
8
  description = "A lightweight, pluggable admin panel for FastAPI"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"