Skip to main content

The simplest way to have a rest api

Project description

Lint Build and Test Upload Package PyPI version

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.

#main.py

from py_easy_rest.server import App


config = {
    "name": "Project Name",
    "schemas": [{
        "name": "Mock",
        "slug": "mock",
        "properties": {
            "name": {"type": "string"},
            "age": {"type": "integer"},
        },
        "required": ["name"],
    }]
}

pyrApp = App(config)

pyrApp.app.run(
    host='0.0.0.0',
    port=8000,
    debug=True,
    auto_reload=True,
)

Running it

python main.py

Now you can access http://localhost:8000/swagger 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 implement our Repo and pass it to the App:

pyrApp = App(config, 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 implement our Cache and pass it to the App:

pyrApp = App(config, cache=MyOwnCache())

Caches ready to use

Middlewares and Listeners

An instance of a py_easy_rest.server.App has a property called app that is a Sanic app. You can use this property to add middlewares and listeners. Take a look at the docs: Middlewares, Take a look at the docs: Listeners

API Description

Properties you could pass to py_easy_rest.server.App:

Properties Required Default Description
api_config True None Object with project and schemas config
repo False MemoryRepo() Repository used as data resource
cache False DummyCache() 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-easy-rest-0.4.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

py_easy_rest-0.4.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file py-easy-rest-0.4.0.tar.gz.

File metadata

  • Download URL: py-easy-rest-0.4.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for py-easy-rest-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ea0a05aa34bdae9885a26adf47d77d045fbf0f6767fb2686a26c835b87a2639d
MD5 bb56d17bca15a280524d18fea5a85310
BLAKE2b-256 00f311c825030b129b5dddbde6e59d11a0cf448645cbedfaee899653c8d6fe8c

See more details on using hashes here.

File details

Details for the file py_easy_rest-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: py_easy_rest-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for py_easy_rest-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 911962acaa86954f8400005048294588c5eeb64bd32d39380cc71ce16ec628cb
MD5 97a83e648d2ac21b1fcd966880ab9aa5
BLAKE2b-256 0b834e9846818db9d58bd1f49949fe907c934d83f60bc5e5f184972e5707d2ff

See more details on using hashes here.

Supported by

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