MCP ExplorerExplorer

Papaya

@lychee-developmenton a year ago
164 MIT
FreeCommunity
AI Systems
Lychee @ Cased MCP hackathon

Overview

What is Papaya

Datafruit is a Python library designed for managing database schemas through simple, declarative data models. It allows developers to define their database tables and fields as Python classes, leveraging features such as migrations and database management with ease.

Use cases

Datafruit is ideal for use in Python applications that require a structured approach to handling database schemas. It is particularly useful for developers building web applications, APIs, or any project where defining, modifying, and managing database tables programmatically is advantageous.

How to use

To use Datafruit, install it via pip, define your data models as classes inheriting from Table and Field, and connect to your database using the appropriate database URL. You can then inspect schema changes using the plan command and apply migrations to your database with the apply command.

Key features

Key features of Datafruit include the ability to declaratively define database models, automatic migration script generation and application, support for schema inspection, and a focus on ease of use for Python developers looking to streamline database management.

Where to use

Datafruit is suitable for use in any Python project that interacts with databases, such as web development frameworks, data analysis applications, and backend services. It can be easily integrated into projects requiring robust database schema management.

Content

datafruit Logo

1. Install Datafruit

pip install datafruit

2. Define Your Data Models

In your Python code, import Datafruit. Declare models as classes:

import datafruit as dft
from datafruit import Table, Field
import os
from dotenv import load_dotenv
from typing import Optional
from datetime import datetime
load_dotenv()

class users(Table, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    username: str = Field(unique=True)
    email: str = Field(unique=True)
    full_name: Optional[str] = None
    is_active: bool = Field(default=True)
    created_at: datetime = Field(default_factory=datetime.utcnow)

class posts(Table, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    title: str = Field(index=True)
    content: str
    published: bool = Field(default=False)
    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: Optional[datetime] = None

db = dft.PostgresDB(
    os.getenv("PG_DB_URL") or "",
    [users, posts]
)

dft.export([db])

3. Inspect Schema Changes

Use the plan command to see pending migrations:

dft plan

This prints a diff of tables/columns to be added, removed, or modified.

4. Apply Migrations

When you’re ready, apply changes to your database:

dft apply

Under the hood, Datafruit generates and runs Alembic migration scripts for you.

You now have a working Datafruit setup: define models in code, preview changes, and apply migrations seamlessly. For more details, see the full documentation.

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers