Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/humbss/sanic-motor-example
Python event-loop application using Sanic and Motor
https://github.com/humbss/sanic-motor-example
Last synced: 30 days ago
JSON representation
Python event-loop application using Sanic and Motor
- Host: GitHub
- URL: https://github.com/humbss/sanic-motor-example
- Owner: humbss
- Created: 2019-12-19T14:50:28.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-08-06T05:24:24.000Z (over 2 years ago)
- Last Synced: 2024-08-03T22:15:49.543Z (4 months ago)
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 21
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-sanic - Sanic + Motor
README
# sanic-motor-example
Python 3+ event-loop application using Sanic as microframework and Motor in the persistence layer.![sanic](https://raw.githubusercontent.com/huge-success/sanic-assets/master/png/sanic-framework-logo-white-400x97.png)
## Setup Project
1. Create virtual environment (in clone directory):
`python3 -m venv ./envi`
Activate the new environment
`source ./envi/bin/activate`
2. Install dependencies
`pip3 install -r requirements.txt `
3. Create .env file with the following content:
`SANIC_dbhost=localhost`
`SANIC_dbport=27017`
4. Bring mongp up with docker-compose file:
`docker-compose up`
5. Run app
`make runserver-dev`
```bash
.
├── api
│ ├── __init__.py
│ ├── routes.py ---> (Routes handler, configure available rest routes)
│ └── user_API.py ---> (User rest service API example)
├── docker-compose.yml ---> (Mongo service)
├── main.py ---> (Application entry point)
├── Makefile ---> (Make scripts)
├── README.md ---> (This file)
├── requirements.txt ---> (Required libs)
├── service
│ └── user_service.py ---> (User api service layer, it deals with DB)
├── tests
│ └── test_user.py ---> (Unit tests)
└── util
├── generic_except.py ---> (Util for exception handling)
├── __init__.py
└── motor_connection.py ---> (Util for DB connection handling)
```## Test Requests
`[POST]` localhost:8000/user/
Payload:
{
"first":"55555555",
"last":"1212"
}
`[GET]` localhost:8000/user/INSERTED-ID
## Unit Tests
The directory `tests` has the unit tests (PyTest) files, you can invoke the test execution with the command:
`pytest`
## DOCSwagger URL: `http://localhost:8000/swagger/`