{"id":13705545,"url":"https://github.com/lixxu/sanic-motor","last_synced_at":"2025-04-12T20:51:43.595Z","repository":{"id":57463850,"uuid":"82188868","full_name":"lixxu/sanic-motor","owner":"lixxu","description":"simple motor wrapper for sanic","archived":false,"fork":false,"pushed_at":"2022-12-22T12:12:31.000Z","size":45,"stargazers_count":58,"open_issues_count":1,"forks_count":14,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-26T15:05:51.562Z","etag":null,"topics":["motor","pymongo","sanic"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lixxu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-16T14:24:06.000Z","updated_at":"2024-03-18T03:36:50.000Z","dependencies_parsed_at":"2023-01-30T08:31:31.409Z","dependency_job_id":null,"html_url":"https://github.com/lixxu/sanic-motor","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixxu%2Fsanic-motor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixxu%2Fsanic-motor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixxu%2Fsanic-motor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixxu%2Fsanic-motor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lixxu","download_url":"https://codeload.github.com/lixxu/sanic-motor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631728,"owners_count":21136560,"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":["motor","pymongo","sanic"],"created_at":"2024-08-02T22:00:43.385Z","updated_at":"2025-04-12T20:51:43.551Z","avatar_url":"https://github.com/lixxu.png","language":"Python","funding_links":[],"categories":["Extensions"],"sub_categories":["ORM"],"readme":"# sanic-motor\nSimple motor wrapper for Sanic.\n\n```\nNotice:\nversion 0.5 requires Sanic \u003e= 21.3\n\nWorks on Sanic \u003e= 0.4.0 and MOTOR_URI need to be defined in app.config\n```\n\n## Installation\n\n`pip install sanic-motor`\n\n## Usage\n\n```python\n#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nfrom sanic import Sanic\nfrom sanic.response import json\nfrom sanic_jinja2 import SanicJinja2\n\nfrom sanic_motor import BaseModel\n\napp = Sanic(__name__)\n\nsettings = dict(\n    MOTOR_URI='mongodb://localhost:27017/myapp', LOGO=None\n)\napp.config.update(settings)\n\nBaseModel.init_app(app)\njinja = SanicJinja2(app, autoescape=True)\n\n\nclass User(BaseModel):\n    __coll__ = 'users'\n    __unique_fields__ = ['name']\n    # __unique_fields__ = ['name, age']   # name and age for unique\n\n\n@app.route('/')\nasync def index(request):\n    cur = await User.find(sort='name')\n    return jinja.render('index.html', request, users=cur.objects)\n\n\n@app.route(\"/show/\u003cid\u003e\")\nasync def show(request, id):\n    # add as_raw = True to get the dict format record\n    user_dict = await User.find_one(id, as_raw=True)\n\n    # user = await User.find_one(id)\n    return json(dict(user=user_dict))\n\n\nif __name__ == '__main__':\n    app.run(host='127.0.0.1', port=8000, debug=True)\n\n```\nsee examples and source code for details.\n\nRun example:\n\n    $cd example\n    $virtualenv venv\n    $. venv/bin/activate\n    $pip install -r requirements.txt\n    $python myapp.py\n\nOpen \u003chttp://localhost:8000\u003e to see the example page.\n\n![example](/example/example.png \"example\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flixxu%2Fsanic-motor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flixxu%2Fsanic-motor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flixxu%2Fsanic-motor/lists"}