{"id":21329965,"url":"https://github.com/swarmauri/crouton","last_synced_at":"2025-07-12T08:32:24.860Z","repository":{"id":258115310,"uuid":"869969113","full_name":"swarmauri/crouton","owner":"swarmauri","description":"A CRUD Router for Fast-Creation of CRUD Routes","archived":false,"fork":false,"pushed_at":"2025-01-23T03:30:31.000Z","size":238,"stargazers_count":9,"open_issues_count":8,"forks_count":5,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-25T17:58:11.023Z","etag":null,"topics":["crud","fastapi","python","router","routing","swarmauri"],"latest_commit_sha":null,"homepage":"https://swarmauri.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swarmauri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-09T08:07:24.000Z","updated_at":"2025-02-01T19:02:50.000Z","dependencies_parsed_at":"2024-10-24T21:31:16.815Z","dependency_job_id":"1b256ea0-ae39-403d-b394-17ab84021bf0","html_url":"https://github.com/swarmauri/crouton","commit_stats":null,"previous_names":["swarmauri/swarmauri-api-crudrouter"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/swarmauri/crouton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarmauri%2Fcrouton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarmauri%2Fcrouton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarmauri%2Fcrouton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarmauri%2Fcrouton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swarmauri","download_url":"https://codeload.github.com/swarmauri/crouton/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swarmauri%2Fcrouton/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264962442,"owners_count":23689812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crud","fastapi","python","router","routing","swarmauri"],"created_at":"2024-11-21T22:13:25.191Z","updated_at":"2025-07-12T08:32:24.848Z","avatar_url":"https://github.com/swarmauri.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/swarmauri/crouton/\"\u003e\u003cimg src=\"https://res.cloudinary.com/dbjmpekvl/image/upload/v1730099724/Swarmauri-logo-lockup-2048x757_hww01w.png\" alt=\"Swamauri Logo\"/\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://hits.sh/github.com/swarmauri/crouton/\"\u003e\u003cimg src=\"https://hits.sh/github.com/swarmauri/swarmakit.svg\" alt=\"Hits\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://opensource.org/licenses/Apache-2.0\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-Apache_2.0-blue.svg\" alt=\"License\"/\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://pypi.org/project/crouton/\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/crouton?label=Crouton\" alt=\"PyPI - Crouton Version\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/crouton/\"\u003e\u003cimg src=\"https://img.shields.io/pypi/dm/crouton?label=Crouton%20Downloads\" alt=\"PyPI - Crouton Downloads\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/crouton-client/\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/crouton-client?label=Crouton-Client\" alt=\"PyPI - Crouton-Client Version\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/crouton-client/\"\u003e\u003cimg src=\"https://img.shields.io/pypi/dm/crouton-client?label=Crouton-Client%20Downloads\" alt=\"PyPI - Crouton-Client Downloads\"/\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Python-3776AB?style=for-the-badge\u0026logo=python\u0026labelColor=black\" alt=\"Python\"/\u003e\n\u003c/p\u003e\n\n---\n\n# Crouton\n\ncrouton streamlines CRUD operations in FastAPI applications by auto-generating endpoints for SQLAlchemy models, reducing the need for repetitive code and improving development speed.\n\nBy integrating Pydantic for data validation, Crouton ensures type safety and consistent data handling, allowing developers to focus on application logic instead of boilerplate code.\n\n# Installation\n\n## Prerequisites\n\nTo install Crouton libraries. Run the following command:\n\n```bash\npip install crouton\npip install crouton-client\n```\n\n### Development Release Installation\n```bash\npip install crouton --pre\npip install crouton-client --pre\n```\n\n# Basic Usage\nBelow is a simple example of what the CRUDRouter can do. In just ten lines of code, you can generate all the crud routes you need for any model. A full list of the routes generated can be found here.\n\n```python\nfrom sqlalchemy import Column, String, Float, Integer\nfrom sqlalchemy import create_engine\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom sqlalchemy.orm import sessionmaker\n\nfrom pydantic import BaseModel\nfrom fastapi import FastAPI\nfrom crouton import SQLAlchemyCRUDRouter\n\napp = FastAPI()\nengine = create_engine(\n    \"sqlite:///./app.db\",\n    connect_args={\"check_same_thread\": False}\n)\n\nSessionLocal = sessionmaker(\n    autocommit=False,\n    autoflush=False,\n    bind=engine\n)\n\nBase = declarative_base()\n\n\ndef get_db():\n    session = SessionLocal()\n    try:\n        yield session\n        session.commit()\n    finally:\n        session.close()\n\n\nclass PotatoCreate(BaseModel):\n    thickness: float\n    mass: float\n    color: str\n    type: str\n\n\nclass Potato(PotatoCreate):\n    id: int\n\n    class Config:\n        orm_mode = True\n\n\nclass PotatoModel(Base):\n    __tablename__ = 'potatoes'\n    id = Column(Integer, primary_key=True, index=True)\n    thickness = Column(Float)\n    mass = Column(Float)\n    color = Column(String)\n    type = Column(String)\n\n\nBase.metadata.create_all(bind=engine)\n\nrouter = SQLAlchemyCRUDRouter(\n    schema=Potato,\n    create_schema=PotatoCreate,\n    db_model=PotatoModel,\n    db=get_db,\n    prefix='potato'\n)\n\napp.include_router(router)\n\n```\n\n# Example\n![image](https://github.com/user-attachments/assets/22e6ce3a-6eb1-4a80-a37f-93fef545b49e)\n\n---\n\n# Using the CroutonClient\n\n`CroutonClient` is a Python library for streamlined REST API interactions, supporting both **synchronous** and **asynchronous** operations for CRUD tasks.\n\n---\n\n### **Initialization**\n```python\nfrom crouton_client import CroutonClient\n\nclient = CroutonClient(API_ROOT=\"https://api.example.com\", ACCESS_STRING=\"your-token\")\n```\n\n---\n\n### **Common Operations**\n\n#### **GET**\n- **Synchronous**:\n  ```python\n  response = client.get(resource=\"items\", item_id=\"123\", filters={\"status\": \"active\"})\n  ```\n- **Asynchronous**:\n  ```python\n  response = await client.aget(resource=\"items\", item_id=\"123\")\n  ```\n\n#### **POST**\n- **Synchronous**:\n  ```python\n  response = client.post(resource=\"items\", data_obj={\"name\": \"Item\", \"price\": 10.0})\n  ```\n- **Asynchronous**:\n  ```python\n  response = await client.apost(resource=\"items\", data_obj={\"name\": \"Item\", \"price\": 10.0})\n  ```\n\n#### **PUT**\n- **Synchronous**:\n  ```python\n  response = client.put(resource=\"items\", data_obj={\"price\": 15.0}, item_id=\"123\")\n  ```\n- **Asynchronous**:\n  ```python\n  response = await client.aput(resource=\"items\", data_obj={\"price\": 15.0}, item_id=\"123\")\n  ```\n\n#### **DELETE**\n- **Synchronous**:\n  ```python\n  response = client.delete(resource=\"items\", item_id=\"123\")\n  ```\n- **Asynchronous**:\n  ```python\n  response = await client.adelete(resource=\"items\", item_id=\"123\")\n  ```\n\n---\n\n### **Features**\n1. **Synchronous \u0026 Asynchronous**: Methods available for GET, POST, PUT, DELETE.\n2. **Authentication**: Pass `ACCESS_STRING` for token-based requests.\n3. **Auto-Generated IDs**: `post` and `apost` auto-generate `id` fields if not provided.\n4. **Logging**: Logs all requests and responses for debugging.\n\n---\n\n### **Error Handling**\nRaises `ValueError` for failed requests:\n```python\ntry:\n    client.get(resource=\"invalid\")\nexcept ValueError as e:\n    print(f\"Error: {e}\")\n```\n\n---\n\n### **Summary Table**\n\n| Operation | Synchronous         | Asynchronous       |\n|-----------|----------------------|--------------------|\n| **GET**   | `get()`              | `aget()`           |\n| **POST**  | `post()`             | `apost()`          |\n| **PUT**   | `put()`              | `aput()`           |\n| **DELETE**| `delete()`           | `adelete()`        |\n\n`CroutonClient` simplifies REST API interactions, allowing you to focus on application logic instead of repetitive request handling.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswarmauri%2Fcrouton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswarmauri%2Fcrouton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswarmauri%2Fcrouton/lists"}