Skip to main content

Create a web interface to interact with a class

Project description

PyObjectInterface

Tests Badge Python Version Badge License Badge

Quickly control any python object through an async web interface.

pip install PyObjectInterface

from PyObjectInterface.WebController import create_WebController
import flask

app = flask.Flask('Demo')
any_python_object = ...
create_WebController(any_python_object, 'any_python_object', app)
app.run()

Go to http://127.0.0.1:5000/webcontroller

Example: Async Robot Control

async_robot_control.png

The above interface was automatically created from:

class DriveMotor:
    def __init__(self, pin):
        self.pin = pin
        self.speed = 0

    def forward(self): ...
    def stop(self): ...

class Robot:
    def __init__(self):
        self.left_motor = DriveMotor(1)
        self.right_motor = DriveMotor(2)

    def forward(self): ...
    def stop(self): ...
    def left(self): ...
    def right(self): ...

Look at PyObjectInterface/examples/example.py for more information.

Advanced Usage and Settings

You can use PyObjectInterface without the WebController.

create_WebController

  • obj: Any python object
  • name: str: Friendly name for object, generally the name of the variable that refers to the object
  • flask_app: return value of flask.Flask()
  • recursion_depth = 5: maximum layers of subobjects to include
  • create_private_interface = True: if True creates a /webcontroller/private page that includes private methods and attributes

Modifying Attributes

By default, POI treats NoneType, bool, int, float, str, list, dict, tuple, and set as primitive types. These show up in the attribute table instead of as recursive objects.

numpy.ndarray, pandas.DataFrame, and pandas.Series are also treated as primitives.

Note: numpy 2.0 arrays currently do not work with python's inspect library, and therefore must be treated as a primitive.

If you would like to customize this behavior, you can modify PyObjectInterface.basic_attribute_types

For example:

from PyObjectInterface import basic_attribute_types

class My_Class_A: ...
class My_Class_B: ...
class My_Class_C: ...

basic_attribute_types[str(type(My_Class_A()))] = False
basic_attribute_types[str(type(My_Class_B()))] = True

My_Class_A will be treated as a primitive and only show up in the attributes table. My_Class_B will also show up in attributes table, but it still appears in the subobjects section. My_Class_C will only appear in the subobjects section.

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

pyobjectinterface-0.1.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

PyObjectInterface-0.1.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file pyobjectinterface-0.1.2.tar.gz.

File metadata

  • Download URL: pyobjectinterface-0.1.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pyobjectinterface-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4390d0e15d230b90d0f51cfdde8e44f161a9d51a54af0c4af58e8d6cc289db9b
MD5 e9fd7234010a1bd4d0b928c2700b53a9
BLAKE2b-256 ae32b2b39a6f464d7c4fe0eee2705b3ea60b90ed96ebfd7fe6d7afecde6ddcff

See more details on using hashes here.

File details

Details for the file PyObjectInterface-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for PyObjectInterface-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 88504c7e074b90dcc385405edc9e72ecb642ec84f0b7bfdd1a706690f7ffc544
MD5 8a970652457932d0d6d840e932ea9526
BLAKE2b-256 8f814172bedeee64f67e995b273164f0c4d68def7ab10e18d7bfaee7ea1044a9

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