fastapi-rabbit-admin


Namefastapi-rabbit-admin JSON
Version 0.1.25 PyPI version JSON
download
home_pagehttps://github.com/yourusername/rabbit-admin
SummaryA FastAPI admin dashboard for Tortoise ORM models
upload_time2025-10-23 08:14:29
maintainerNone
docs_urlNone
authorYour Name
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Rabbit Admin

A modern, production-ready admin dashboard for FastAPI applications using Tortoise ORM. Automatically generates CRUD interfaces for your database models with a beautiful Quasar-based frontend.

## Features

- 🚀 **Auto-generated CRUD interfaces** - Register your Tortoise ORM models and get full CRUD functionality
- 🎨 **Modern UI** - Built with Quasar Framework (Vue.js)
- 🔗 **Relations Support** - Handles ForeignKey and ManyToMany relationships
- 📝 **Field Types** - Supports all common field types including JSON, DateTime, Boolean, and more
- 🎯 **Easy Integration** - Mount to any existing FastAPI application
- 📦 **Zero Configuration** - Works out of the box with sensible defaults

## Installation

### From PyPI (when published)

```bash
pip install rabbit-admin
```

### From Source

```bash
# Clone the repository
git clone https://github.com/yourusername/rabbit-admin.git
cd rabbit-admin/backend

# Install in development mode
pip install -e .

# Or install directly
pip install .
```

## Quick Start

### 1. Define Your Models

```python
from tortoise import fields, models

class Product(models.Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=255)
    price = fields.FloatField()
    is_available = fields.BooleanField(default=True)
    
    def __str__(self):
        return self.name
```

### 2. Set Up Your FastAPI Application

```python
from fastapi import FastAPI
from tortoise.contrib.fastapi import register_tortoise
from rabbit_admin import admin_app
from contextlib import asynccontextmanager

# Import your models
from your_app.models import Product, Category

@asynccontextmanager
async def lifespan(app: FastAPI):
    # Register your models with admin
    await admin_app.register(Product)
    await admin_app.register(Category)
    
    yield

app = FastAPI(lifespan=lifespan)

# Mount the admin router and UI
app.include_router(admin_app.router)
admin_app.mount_ui(app, path="/dash")

# Configure Tortoise ORM
TORTOISE_ORM = {
    "connections": {
        "default": "sqlite://./db.sqlite3"
        # Or use PostgreSQL: "postgres://user:pass@localhost:5432/dbname"
    },
    "apps": {
        "models": {
            "models": ["your_app.models", "aerich.models"],
            "default_connection": "default",
        },
    },
}

register_tortoise(
    app,
    config=TORTOISE_ORM,
    generate_schemas=True,
    add_exception_handlers=True,
)
```

### 3. Run Your Application

```bash
uvicorn your_app.main:app --reload
```

### 4. Access the Admin Dashboard

Navigate to:
- Admin API: `http://localhost:8000/api/admin/_models`
- Admin UI: `http://localhost:8000/dash` (mounted via admin_app.mount_ui)
- API Docs: `http://localhost:8000/docs`

## Advanced Usage

### Custom Admin Base URL

```python
from rabbit_admin.adminV2 import AdminRegistry

# Create admin with custom base URL
custom_admin = AdminRegistry(base_url="/custom-admin")

# Register models
await custom_admin.register(YourModel)

# Mount to app
app.include_router(custom_admin.router)
```

### Serving the Admin UI

The admin UI is a pre-built Quasar application. To serve it, use the `mount_ui` method:

```python
# Mount the admin UI (do this AFTER including the router)
app.include_router(admin_app.router)
admin_app.mount_ui(app, path="/dash")
```

You can customize the mount path:

```python
# Mount at a different path
admin_app.mount_ui(app, path="/admin-ui")
# UI will be available at http://localhost:8000/admin-ui
```

**Note**: The static files are automatically included in the package installation. The `mount_ui` method handles finding and serving them correctly.

### Model Registration Options

```python
# Simple registration
await admin_app.register(Product)

# Register multiple models
for model in [Product, Category, Order]:
    await admin_app.register(model)
```

## API Endpoints

Once registered, each model gets the following endpoints:

- `GET /api/admin/{model_name}` - List all records
- `POST /api/admin/{model_name}` - Create a new record
- `GET /api/admin/{model_name}/{id}` - Get a specific record
- `PUT /api/admin/{model_name}/{id}` - Update a record
- `DELETE /api/admin/{model_name}/{id}` - Delete a record
- `GET /api/admin/{model_name}/form` - Get form schema for the model
- `GET /api/admin/_models` - Get all registered models

## Supported Field Types

- **IntField** - Integer numbers
- **CharField** - Short text
- **TextField** - Long text
- **FloatField** - Decimal numbers
- **BooleanField** - True/False
- **DatetimeField** - Date and time
- **DateField** - Date only
- **TimeField** - Time only
- **JSONField** - JSON data
- **ForeignKeyField** - Foreign key relationships
- **ManyToManyField** - Many-to-many relationships

## Example Application

See `example_app.py` in the repository for a complete working example.

```bash
# Run the example
cd backend
python example_app.py
```

## Development

### Project Structure

```
backend/
├── __init__.py          # Package initialization
├── adminV2.py           # Core admin functionality
├── admin.py             # Legacy admin (V1)
├── decor.py             # Decorators and utilities
├── models.py            # Empty - for your models
├── example_app.py       # Example application
├── static/              # Frontend build files
├── setup.py             # Package setup
└── README.md            # This file
```

### Building the Frontend

The frontend is built using Quasar Framework:

```bash
cd frontend
npm install
npm run build  # or: quasar build

# The build output goes to backend/static/
```

### Running Tests

```bash
pip install -e ".[dev]"
pytest
```

## Requirements

- Python >= 3.8
- FastAPI >= 0.104.0
- Tortoise ORM >= 0.20.0
- Pydantic >= 2.0.0

## CORS Configuration

For development with a separate frontend server:

```python
from fastapi.middleware.cors import CORSMiddleware

app.add_middleware(
    CORSMiddleware,
    allow_origins=["http://localhost:9000"],  # Your frontend URL
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)
```

## Troubleshooting

### Models not appearing in admin

- Ensure you've registered the model: `await admin_app.register(YourModel)`
- Check that Tortoise ORM is properly initialized
- Verify the model is imported before registration

### Frontend not loading

- Ensure you've called `admin_app.mount_ui(app, path="/dash")`
- Mount the UI AFTER including the router: `app.include_router(admin_app.router)`
- Verify the UI is accessible at the correct path (e.g., `http://localhost:8000/dash`)
- Check that the static files are included in your package installation

### CORS errors

- Add your frontend URL to CORS allowed origins
- Ensure CORS middleware is added before routes

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

MIT License - see LICENSE file for details

## Credits

- Built with [FastAPI](https://fastapi.tiangolo.com/)
- Database ORM: [Tortoise ORM](https://tortoise.github.io/)
- Frontend: [Quasar Framework](https://quasar.dev/)

## Support

For issues, questions, or contributions, please visit:
- GitHub: https://github.com/yourusername/rabbit-admin
- Issues: https://github.com/yourusername/rabbit-admin/issues


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/yourusername/rabbit-admin",
    "name": "fastapi-rabbit-admin",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Your Name",
    "author_email": "Your Name <your.email@example.com>",
    "download_url": "https://files.pythonhosted.org/packages/ee/91/21f59aadeccd97aa8701f72eae292452e50537514e3d797f2216325a2787/fastapi_rabbit_admin-0.1.25.tar.gz",
    "platform": null,
    "description": "# Rabbit Admin\n\nA modern, production-ready admin dashboard for FastAPI applications using Tortoise ORM. Automatically generates CRUD interfaces for your database models with a beautiful Quasar-based frontend.\n\n## Features\n\n- \ud83d\ude80 **Auto-generated CRUD interfaces** - Register your Tortoise ORM models and get full CRUD functionality\n- \ud83c\udfa8 **Modern UI** - Built with Quasar Framework (Vue.js)\n- \ud83d\udd17 **Relations Support** - Handles ForeignKey and ManyToMany relationships\n- \ud83d\udcdd **Field Types** - Supports all common field types including JSON, DateTime, Boolean, and more\n- \ud83c\udfaf **Easy Integration** - Mount to any existing FastAPI application\n- \ud83d\udce6 **Zero Configuration** - Works out of the box with sensible defaults\n\n## Installation\n\n### From PyPI (when published)\n\n```bash\npip install rabbit-admin\n```\n\n### From Source\n\n```bash\n# Clone the repository\ngit clone https://github.com/yourusername/rabbit-admin.git\ncd rabbit-admin/backend\n\n# Install in development mode\npip install -e .\n\n# Or install directly\npip install .\n```\n\n## Quick Start\n\n### 1. Define Your Models\n\n```python\nfrom tortoise import fields, models\n\nclass Product(models.Model):\n    id = fields.IntField(pk=True)\n    name = fields.CharField(max_length=255)\n    price = fields.FloatField()\n    is_available = fields.BooleanField(default=True)\n    \n    def __str__(self):\n        return self.name\n```\n\n### 2. Set Up Your FastAPI Application\n\n```python\nfrom fastapi import FastAPI\nfrom tortoise.contrib.fastapi import register_tortoise\nfrom rabbit_admin import admin_app\nfrom contextlib import asynccontextmanager\n\n# Import your models\nfrom your_app.models import Product, Category\n\n@asynccontextmanager\nasync def lifespan(app: FastAPI):\n    # Register your models with admin\n    await admin_app.register(Product)\n    await admin_app.register(Category)\n    \n    yield\n\napp = FastAPI(lifespan=lifespan)\n\n# Mount the admin router and UI\napp.include_router(admin_app.router)\nadmin_app.mount_ui(app, path=\"/dash\")\n\n# Configure Tortoise ORM\nTORTOISE_ORM = {\n    \"connections\": {\n        \"default\": \"sqlite://./db.sqlite3\"\n        # Or use PostgreSQL: \"postgres://user:pass@localhost:5432/dbname\"\n    },\n    \"apps\": {\n        \"models\": {\n            \"models\": [\"your_app.models\", \"aerich.models\"],\n            \"default_connection\": \"default\",\n        },\n    },\n}\n\nregister_tortoise(\n    app,\n    config=TORTOISE_ORM,\n    generate_schemas=True,\n    add_exception_handlers=True,\n)\n```\n\n### 3. Run Your Application\n\n```bash\nuvicorn your_app.main:app --reload\n```\n\n### 4. Access the Admin Dashboard\n\nNavigate to:\n- Admin API: `http://localhost:8000/api/admin/_models`\n- Admin UI: `http://localhost:8000/dash` (mounted via admin_app.mount_ui)\n- API Docs: `http://localhost:8000/docs`\n\n## Advanced Usage\n\n### Custom Admin Base URL\n\n```python\nfrom rabbit_admin.adminV2 import AdminRegistry\n\n# Create admin with custom base URL\ncustom_admin = AdminRegistry(base_url=\"/custom-admin\")\n\n# Register models\nawait custom_admin.register(YourModel)\n\n# Mount to app\napp.include_router(custom_admin.router)\n```\n\n### Serving the Admin UI\n\nThe admin UI is a pre-built Quasar application. To serve it, use the `mount_ui` method:\n\n```python\n# Mount the admin UI (do this AFTER including the router)\napp.include_router(admin_app.router)\nadmin_app.mount_ui(app, path=\"/dash\")\n```\n\nYou can customize the mount path:\n\n```python\n# Mount at a different path\nadmin_app.mount_ui(app, path=\"/admin-ui\")\n# UI will be available at http://localhost:8000/admin-ui\n```\n\n**Note**: The static files are automatically included in the package installation. The `mount_ui` method handles finding and serving them correctly.\n\n### Model Registration Options\n\n```python\n# Simple registration\nawait admin_app.register(Product)\n\n# Register multiple models\nfor model in [Product, Category, Order]:\n    await admin_app.register(model)\n```\n\n## API Endpoints\n\nOnce registered, each model gets the following endpoints:\n\n- `GET /api/admin/{model_name}` - List all records\n- `POST /api/admin/{model_name}` - Create a new record\n- `GET /api/admin/{model_name}/{id}` - Get a specific record\n- `PUT /api/admin/{model_name}/{id}` - Update a record\n- `DELETE /api/admin/{model_name}/{id}` - Delete a record\n- `GET /api/admin/{model_name}/form` - Get form schema for the model\n- `GET /api/admin/_models` - Get all registered models\n\n## Supported Field Types\n\n- **IntField** - Integer numbers\n- **CharField** - Short text\n- **TextField** - Long text\n- **FloatField** - Decimal numbers\n- **BooleanField** - True/False\n- **DatetimeField** - Date and time\n- **DateField** - Date only\n- **TimeField** - Time only\n- **JSONField** - JSON data\n- **ForeignKeyField** - Foreign key relationships\n- **ManyToManyField** - Many-to-many relationships\n\n## Example Application\n\nSee `example_app.py` in the repository for a complete working example.\n\n```bash\n# Run the example\ncd backend\npython example_app.py\n```\n\n## Development\n\n### Project Structure\n\n```\nbackend/\n\u251c\u2500\u2500 __init__.py          # Package initialization\n\u251c\u2500\u2500 adminV2.py           # Core admin functionality\n\u251c\u2500\u2500 admin.py             # Legacy admin (V1)\n\u251c\u2500\u2500 decor.py             # Decorators and utilities\n\u251c\u2500\u2500 models.py            # Empty - for your models\n\u251c\u2500\u2500 example_app.py       # Example application\n\u251c\u2500\u2500 static/              # Frontend build files\n\u251c\u2500\u2500 setup.py             # Package setup\n\u2514\u2500\u2500 README.md            # This file\n```\n\n### Building the Frontend\n\nThe frontend is built using Quasar Framework:\n\n```bash\ncd frontend\nnpm install\nnpm run build  # or: quasar build\n\n# The build output goes to backend/static/\n```\n\n### Running Tests\n\n```bash\npip install -e \".[dev]\"\npytest\n```\n\n## Requirements\n\n- Python >= 3.8\n- FastAPI >= 0.104.0\n- Tortoise ORM >= 0.20.0\n- Pydantic >= 2.0.0\n\n## CORS Configuration\n\nFor development with a separate frontend server:\n\n```python\nfrom fastapi.middleware.cors import CORSMiddleware\n\napp.add_middleware(\n    CORSMiddleware,\n    allow_origins=[\"http://localhost:9000\"],  # Your frontend URL\n    allow_credentials=True,\n    allow_methods=[\"*\"],\n    allow_headers=[\"*\"],\n)\n```\n\n## Troubleshooting\n\n### Models not appearing in admin\n\n- Ensure you've registered the model: `await admin_app.register(YourModel)`\n- Check that Tortoise ORM is properly initialized\n- Verify the model is imported before registration\n\n### Frontend not loading\n\n- Ensure you've called `admin_app.mount_ui(app, path=\"/dash\")`\n- Mount the UI AFTER including the router: `app.include_router(admin_app.router)`\n- Verify the UI is accessible at the correct path (e.g., `http://localhost:8000/dash`)\n- Check that the static files are included in your package installation\n\n### CORS errors\n\n- Add your frontend URL to CORS allowed origins\n- Ensure CORS middleware is added before routes\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nMIT License - see LICENSE file for details\n\n## Credits\n\n- Built with [FastAPI](https://fastapi.tiangolo.com/)\n- Database ORM: [Tortoise ORM](https://tortoise.github.io/)\n- Frontend: [Quasar Framework](https://quasar.dev/)\n\n## Support\n\nFor issues, questions, or contributions, please visit:\n- GitHub: https://github.com/yourusername/rabbit-admin\n- Issues: https://github.com/yourusername/rabbit-admin/issues\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A FastAPI admin dashboard for Tortoise ORM models",
    "version": "0.1.25",
    "project_urls": {
        "Documentation": "https://github.com/yourusername/rabbit-admin",
        "Homepage": "https://github.com/yourusername/rabbit-admin",
        "Repository": "https://github.com/yourusername/rabbit-admin"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9574eaf50b4fd827a91cdee68ab1e50135955fed1b9a948e4a60935e97d3fa3c",
                "md5": "89f34c6e82975f3db9e6d8b2b858aa32",
                "sha256": "22d6e956452a8c224b225c0c5cb4f4d9ee4cb7699785db1608cbfb3bee196a63"
            },
            "downloads": -1,
            "filename": "fastapi_rabbit_admin-0.1.25-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "89f34c6e82975f3db9e6d8b2b858aa32",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 797513,
            "upload_time": "2025-10-23T08:14:27",
            "upload_time_iso_8601": "2025-10-23T08:14:27.972172Z",
            "url": "https://files.pythonhosted.org/packages/95/74/eaf50b4fd827a91cdee68ab1e50135955fed1b9a948e4a60935e97d3fa3c/fastapi_rabbit_admin-0.1.25-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ee9121f59aadeccd97aa8701f72eae292452e50537514e3d797f2216325a2787",
                "md5": "85fd1619691370be6d6b75f7e2b6b6db",
                "sha256": "634a5106bf7bff04e13ad4c09cae2449c3697dfd176e1e286325045e43897e83"
            },
            "downloads": -1,
            "filename": "fastapi_rabbit_admin-0.1.25.tar.gz",
            "has_sig": false,
            "md5_digest": "85fd1619691370be6d6b75f7e2b6b6db",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 773713,
            "upload_time": "2025-10-23T08:14:29",
            "upload_time_iso_8601": "2025-10-23T08:14:29.946125Z",
            "url": "https://files.pythonhosted.org/packages/ee/91/21f59aadeccd97aa8701f72eae292452e50537514e3d797f2216325a2787/fastapi_rabbit_admin-0.1.25.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-23 08:14:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yourusername",
    "github_project": "rabbit-admin",
    "github_not_found": true,
    "lcname": "fastapi-rabbit-admin"
}
        
Elapsed time: 2.98721s