Skip to main content

Bottle-wrapper to make python objects accessible via HTTP API

Project description

Nimrodel

A simple Bottle.py-wrapper to provide HTTP API access to any python object.

Requirements

Quick Start

Install with

pip install nimrodel

Create your API with

from nimrodel import API

myapi = API()

You may optionally pass a port number with port=42, a path with path="api" and whether you want to serve on IPv4 (IPv6=False). You can also give the API object an existing bottle server (server=bottleobject), in which case your API will be served on the existing server. It is heavily recommended to also pass a path variable to separate API from regular routing of your server. You may also pass a custom function with parsedoc=yourfunction that takes your method as input and returns a dictionary with the values desc for the function description, params for a dictionary of parameter names mapped to a dictionary and returns for a dictionary of the return value. Both return and param dictionaries can have the keys type and desc for data type and description respectively. By default nimrodel will attempt to parse your docstring according to the reST standard (Sphinx).

Then make any class accessible with a decorator.

@myapi.apiclass("group")
class Group:

	def __init__(self,name,apipath,songs):
		# some stuff
		self.__apiname__ = apipath

Any instance of that class is now accessible via the combination of class path and its individual path. Now just decorate the methods. All its arguments can be passed via URI query arguments.

	@myapi.get("songs")
	def get_songs(self,member):
		return {"songs":[s["title"] for s in self.songs if member in s["performers"]]}

Now create an object and make sure it has an __apiname__ attribute:

e = Group("Exid","exid",exidsongs)

Then you can access its methods with simple HTTP calls:

HTTP GET http://localhost:1337/group/exid/songs?member=Junghwa

For more in-depth exploration of the possibilities, refer to the file example.py included in the repository.

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

nimrodel-0.3.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

nimrodel-0.3.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file nimrodel-0.3.0.tar.gz.

File metadata

  • Download URL: nimrodel-0.3.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for nimrodel-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8fecb1ff1d621000007a3ab6f1d4ab72565dd7beca45116f007042fd81e9473b
MD5 0fa453f2bf7efe7ceba05b5b21d67e20
BLAKE2b-256 50042d2b5e9de9b0cfdad3ca531b5ca1512475256c70bcc3f70cad5e2ec2cdbc

See more details on using hashes here.

File details

Details for the file nimrodel-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: nimrodel-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for nimrodel-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90501321e01842b48e18de52a5d316e834a9c8a8a12ab22e7a38d85de6c4c1b8
MD5 70f3172ccc94fb7107093b54e4f4b661
BLAKE2b-256 30dd708f2518db24514e21119bf694bb25ec2189aac2410c2c83e26415391a33

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