Skip to main content

The package provides enhanced support for writing REST APIs with Muffin framework

Project description

Muffin‑REST

Muffin‑REST simplifies building RESTful APIs with Muffin by offering:

  • Declarative API class with resource registration
  • Built-in filtering, sorting, pagination, and search
  • Support for:
  • Swagger/OpenAPI autodocumentation
  • Works with asyncio, Trio, and Curio

Tests Status PyPI Version Python Versions

Requirements

  • Python >= 3.10
  • Trio requires Peewee backend

Installation

Install core package:

pip install muffin-rest

Add optional backend support:

  • SQLAlchemy Core: pip install muffin-rest[sqlalchemy]
  • Peewee ORM: pip install muffin-rest[peewee]
  • YAML support for Swagger: pip install muffin-rest[yaml]

Quickstart (Peewee example)

from muffin import Application
from muffin_rest import API
from muffin_rest.peewee import PeeweeEndpoint
from models import User  # your Peewee model

app = Application("myapp")
api = API(title="User Service", version="1.0")

@api.route
class UsersEndpoint(PeeweeEndpoint):
    class Meta:
        model = User
        lookup_field = "id"
        filters = ["name", "email"]
        ordering = ["-created_at"]

api.setup(app, prefix="/api", swagger=True)

Endpoints available:

  • GET /api/users/ — list with pagination, search, filtering
  • POST /api/users/ — create
  • GET /api/users/{id}/ — retrieve
  • PUT /api/users/{id}/ — replace
  • PATCH /api/users/{id}/ — update
  • DELETE /api/users/{id}/ — remove
  • Docs: /api/docs/, OpenAPI spec: /api/openapi.json

Usage with SQLAlchemy

from muffin_rest import API
from muffin_rest.sqlalchemy import SAEndpoint
from models import my_table, db_engine

api = API()
@api.route
class MySAEndpoint(SAEndpoint):
    class Meta:
        table = my_table
        database = db_engine

api.setup(app)

Usage with MongoDB

from muffin_rest import API
from muffin_rest.mongo import MongoEndpoint
from models import mongo_collection

api = API()
@api.route
class MyMongoEndpoint(MongoEndpoint):
    class Meta:
        collection = mongo_collection

api.setup(app)

Advanced Configuration

Customize Swagger and routes via constructor:

api = API(
    title="Service API",
    version="2.1",
    swagger_ui=True,
    openapi_path="/api/openapi.json",
    docs_path="/api/docs/"
)

Contributing & Examples

  • See examples/ for live application demos
  • Tests in tests/ focus on filtering, pagination, status codes
  • Check CHANGELOG.md for latest changes

Bug Tracker

Report bugs or request features: https://github.com/klen/muffin-rest/issues

Contributing

Repo: https://github.com/klen/muffin-rest Pull requests, example additions, docs improvements welcome!

Contributors

  • klen (Kirill Klenov)

License

Licensed under the MIT license.

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

muffin_rest-13.5.3.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

muffin_rest-13.5.3-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file muffin_rest-13.5.3.tar.gz.

File metadata

  • Download URL: muffin_rest-13.5.3.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for muffin_rest-13.5.3.tar.gz
Algorithm Hash digest
SHA256 884fea1bcdfbb5597a633a147e89f05bbadeeaa947fd9543e717bf030f22df34
MD5 8d9c21a812a9e4285bd2a6be73989d31
BLAKE2b-256 cc1fe57a2cd1757cb72546cba7e021c3b045a41dc615bd2ff861dcef7c209609

See more details on using hashes here.

File details

Details for the file muffin_rest-13.5.3-py3-none-any.whl.

File metadata

  • Download URL: muffin_rest-13.5.3-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for muffin_rest-13.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 40feb991976c0f768ca84a2cd3e235d03b5a6f9a8ed3d833adaee02bfd082a04
MD5 e4dce095633cb47fda12aeb0292db4a8
BLAKE2b-256 e288f4729d1c7e9590a9605f43a4e60f3ad90f42f36d577748d667ad22775b6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page