Skip to content

Commit

Permalink
Add typing and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mejroslav committed Aug 1, 2023
1 parent 58ad10b commit 58f3650
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions asab/library/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ async def read(self, path: str, tenant: typing.Optional[str] = None) -> typing.O
tenant (str | None): The tenant to apply. If not specified, the global access is assumed.
Returns:
(IO | None) Readable stream with the content of the library item.
`None` is returned if the item is not found or if it is disabled (either globally or for the specified tenant).
( IO | None ): Readable stream with the content of the library item. `None` is returned if the item is not found or if it is disabled (either globally or for the specified tenant).
Examples:
Expand Down Expand Up @@ -327,7 +326,7 @@ async def export(self, path: str = "/", tenant: typing.Optional[str] = None, rem
Args:
path: The path to export.
tenant: The tenant to use for the operation.
tenant (str | None ): The tenant to use for the operation.
remove_path: If `True`, the path will be removed from the tar file.
Returns:
Expand Down Expand Up @@ -382,8 +381,26 @@ async def subscribe(self, paths: typing.Union[str, typing.List[str]]) -> None:
"""
Subscribe to changes for specified paths of the library.
In order to notify on changes in the Library, this method must be used after the Library is ready.
Args:
paths (str | list[str]): Either single path or list of paths to be subscribed. All the paths must be absolute (start with '/').
Examples:
```python
class MyApplication(asab.Application):
async def initialize(self):
self.PubSub.subscribe("Library.ready!", self.on_library_ready
self.PubSub.subscribe("Library.change!", self.on_library_change)
async def on_library_ready(self, event_name, library=None):
await self.LibraryService.subscribe(["/alpha","/beta"])
def on_library_change(self, message, provider, path):
print("New changes in the library found by provider: '{}'".format(provider))
```
"""
if isinstance(paths, str):
paths = [paths]
Expand Down

0 comments on commit 58f3650

Please sign in to comment.