Skip to main content

A package that allows any instance of a class to be referenced with its ID that is provided by this package

Project description


What is It?

The findbyid utility is a package that can keep track of all objects that are created from a class that inherits from the findbyid.FindByIDFactory metaclass. It creates automatically a specific ID for the instance-in-question and provides classmethods to retrieve the object later by its ID.

What Should I use if For?

Let's say that we have a web server and a client. The server provides the client and interface to an object and needs to pass the client a reference to the object of which interface the client is using. Without the findbyid package, the only way would be to serialize the object and send it to the client somehow. Not only would that be not very practical in terms of the amount of network traffic, but also it would make dynamic changes to the object impossible. With the findbyid module though, we can just pass the reference ID to the client. That way the client can access the object by its ID, so that the actual data doesn't need to be carried over.

It is also handy when you have to access a certain object from two different contexts: you just pass the ID instead of the whole object to the other context.

How do I use It?

The usage of the package is simple:

import findbyid

class ExampleClass(findbyid.FindByIDFactory):
    def __init__(self, example_val):

        self.example_val = example_val


instance = ExampleClass("Foo")
print(instance is ExampleClass.findByID(instance.ID))

>>> 98658
>>> True

The ID is random so do not be confused if your ID is different.

In-depth Look

Method signatures and such

  • def __init__(self: object, *args, **kwargs) -> None
    All subclasses need to call the instantiator for the utility to work properly.

  • def findByID(cls, ID: int) -> object:
    Returns an object with the given ID. If no object is found, a NotFoundException is raised.

  • def getInstances(cls) -> list[object]:
    Returns all objects of a class.

  • ID
    The specific tag that is assigned to every instance of a class inheriting from the findbyid.FindByIDFactory metaclass.

Features to be Added

  • A possibility to be able to serialize and save an object to disk and retrieve it using the same ways that it is done currenty with RAM.

Project details

Download files

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

Files for findbyid, version 0.0.7
Filename, size File type Python version Upload date Hashes
Filename, size findbyid-0.0.7.tar.gz (3.0 kB) File type Source Python version None Upload date Hashes View
Filename, size findbyid-0.0.7-py3-none-any.whl (4.5 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page