Findbyid
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):
super().__init__()
self.example_val = example_val
...
instance = ExampleClass("Foo")
print(instance.ID)
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, aNotFoundExceptionis raised.
@classmethod. -
def getInstances(cls) -> list[object]:
Returns all objects of a class.
@classmethod. -
ID
The specific tag that is assigned to every instance of a class inheriting from thefindbyid.FindByIDFactorymetaclass.
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.
Metadata
Release files for findbyid 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| findbyid-0.0.7.tar.gz | 3.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| findbyid-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.6 kB
Release files / findbyid-0.0.7.tar.gz
| Download URL | findbyid-0.0.7.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15e61e2aa264ded72f7313c5e4d4b42569c3b7a41f8ea18fe72c4f72567db7a9
|
|
BLAKE2b-256 checksum How to use checksums |
3eb8da0c76207875b1975cc43499e649d60f55abfea8bb9470f975fe45d337e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Release files / findbyid-0.0.7-py3-none-any.whl
| Download URL | findbyid-0.0.7-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
12e40ca1e6c55b757f63a37631c842dc04e6d431e0eb9e2a42a7ddfd684714be
|
|
BLAKE2b-256 checksum How to use checksums |
cc4874c39fd28bd419609587b387cb56f0524f6ce909edffb79dac6d53b38206
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|