Skip to main content

Sbeaver

This is sbeaver - a lightweight and extremely simple http server for creating APIs.

To install sbeaver on your system, you can use the pip install sbeaver command, or you can download this repository and run python setup.py install

Usage

import sbeaver

server = sbeaver.Server(address="localhost", port=8000, sync=True)

this code will import and make the basic configuration of the sbeaver server in your project To start, you need to call server.start()

Decorators are used to bind paths on the server to internal methods.

sbind is used to bind static paths (e.g. home page)

@server.sbind('/')
def index(request):
    return 200, {'status':'ok'}

image

You can also bind a regular expression using bind

@server.bind(r'/regex/(\w*)(?:\.|/)(\w*)(?:|/)')
def regex(request, param1 = None, param2 = None):
    return 200, {'first':param1, 'second':param2}

image

Or if you can't work with the regex, you can use easy bind(ebind)

@server.ebind('/ebind/<submethod>/<method>')
def method(request,  submethod = None, method = None):
    return 200, {'section':submethod, 'method':method}

image

You can also interact with the user's request. For example, this code will return all known information about a particular request

@server.sbind('/info')
def info(request):
    request.parse_all() # get and save data, url params, ip from request
    return 200, {'info':request.dict}

image

If the function required for the path is not found during request processing, the code404 function is called. It can be assigned by code

@server.code404()
def page_not_found(request):
    return {'error404': f"path {request.path} not found"}

image

Also done with 500 code. When an exception occurs during the processing of a user request, an error will be displayed and the code function will be called

@server.code500()
def internal_server_error(request):
    return {'error500': f"Exception happened"}

Redirecting

You can redirect user to another page using method redirect

Example:

@server.sbind('/') # static bind
def args(request):
    return sbeaver.redirect(307,'/info') # redirect with data(307 code)

Files

You can return files using method file

@server.sbind('/photo')
def photo(request):
    return sbeaver.open_file('beaver.png', sbeaver.Types.Image.png)

Release files for sbeaver 0.7.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sbeaver 0.7.4
File Size Uploaded
sbeaver-0.7.4.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sbeaver 0.7.4
File Interpreter ABI Platform
sbeaver-0.7.4-py3-none-any.whl Python 3 none any Details

Total release size: 21.9 kB

Release files / sbeaver-0.7.4.tar.gz

Download URL sbeaver-0.7.4.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
69ded37fb1d95a88631a6783d027f4281c8e72693c5c35c635bbd843a7409a69
BLAKE2b-256 checksum
How to use checksums
58228d16f9b356fda8932988ae8f7afc2b6a6c280383953996e3054913ec8a3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sbeaver-0.7.4-py3-none-any.whl

Download URL sbeaver-0.7.4-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8741802659f92ca2a50c0db25d2d0d35f4a388df4960c7de0e2a8772e970715c
BLAKE2b-256 checksum
How to use checksums
dfdf6de5c65f80c96f7ce4328c99ef4ceeffe295ad3bf78232d0068e79cc72e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.7.4 This release

2 release files

0.7.2

2 release files

0.7.1

1 release file

0.7.0

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6

1 release file

0.5.1

1 release file

0.5

1 release file

0.4.2.1

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2.1

1 release file

0.1

1 release file

0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page