The simplest way to have a rest api
Project description
py-easy-rest
It is a lib to create fast and scalable rest apis based on JSON schema in a very simple way. It is based on Sanic and it has built in extensions to add repositories and caches.
Getting Started
How to install
pip install py-easy-rest
Coding your app
It will use by default an in memory repository. It is not recommended to production applications. The next sections of this documentation will show you ways to integrate your application with Mongo DB and ways to use cache strategies. You can also create your own repositories and cache strategies to integrate your app with other technologies.
PYRSanicAppBuilder.build
returns a Sanic App, so you can use it to extend and build new things in your app.
#main.py
from py_easy_rest import PYRSanicAppBuilder
from py_easy_rest.service import PYRService
config = {
"name": "Project Name",
"schemas": [{
"name": "Mock",
"slug": "mock",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
},
"required": ["name"],
}]
}
service = PYRService(api_config_mock)
sanic_app = PYRSanicAppBuilder.build(api_config_mock, service)
sanic_app.run(
host='0.0.0.0',
port=8000,
debug=True,
)
Running it
python main.py
Now you can access http://localhost:8000/docs
to access your api documentation.
Integrating with Repositories
It is possible to add a repository to your application persist data into some data base. By default it will use a in memory repository, witch is not recommended to production environment.
To create your own repository, you just need to follow the Repo signature and pass it to the App:
service = PYRService(api_config_mock, repo=MyOwnRepo())
Repos ready to use
Integrating with Cache Strategies
It is possible to add a cache to your application. By default it will not use a cache, but you can choice a built in option or create your own cache.
To create your own cache, you just need to follow the Cache signature and pass it to the App:
service = PYRService(api_config_mock, cache=MyOwnCache())
Caches ready to use
API Description
py_easy_rest.PYRSanicAppBuilder.build()
Properties | Required | Default | Description |
---|---|---|---|
api_config | True | None | Object with project and schemas config |
service | True | PYRService() | Service use to handle the operations |
py_easy_rest.services.PYRService()
Properties | Required | Default | Description |
---|---|---|---|
api_config | True | None | Object with project and schemas config |
repo | False | PYRMemoryRepo() | Repository used as data resource |
cache | False | PYRDummyCache() | Cache strategy |
cache_list_seconds_ttl | False | 10 | TTL to cache the list results in seconds |
cache_get_seconds_ttl | False | 60 * 30 | TTL to cache the get results |
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
Built Distribution
File details
Details for the file py-easy-rest-0.4.4.tar.gz
.
File metadata
- Download URL: py-easy-rest-0.4.4.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b1a930a0faf91b0ef428ddfc7e9d205b755e2bc0641c2f0d71045b5be3a7c03 |
|
MD5 | ea30171118ffc2577d9fad346c969a39 |
|
BLAKE2b-256 | e06a51554c3e1dd6228eab0acbb03c729ec59a39e227c26f81a54fc53ee530cf |
File details
Details for the file py_easy_rest-0.4.4-py3-none-any.whl
.
File metadata
- Download URL: py_easy_rest-0.4.4-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc46cada8e06644f41320b6fadb2743f9bac84d988ce113f84ef7b9561c099df |
|
MD5 | e80a87d2f60c6983f1cbf75a074eabd3 |
|
BLAKE2b-256 | 6b9f23c76d8e9fb183ec64b0fef479152c253d259301b44a08ef48a9837b814e |