zafiaonline.service_generator package

Submodules

zafiaonline.service_generator.helper module

Factory for creating lazily-loaded submodule properties.

This module provides a helper function make_submodule_property() that allows dynamic and lazy initialization of client submodules. It is primarily used inside the Client class of the zafiaonline package to instantiate API submodules (e.g., authentication, rooms, matchmaking) only when they are accessed.

The design follows a combination of the “Lazy Initialization” and “Factory” patterns. Dependencies between submodules are resolved through callable factories, ensuring that the correct references are injected at initialization time.

Example

from zafiaonline.main import Client client = Client() client.auth # lazily instantiates AuthService client.room # lazily instantiates RoomMethods, injecting auth

Typical usage within Client:
auth = make_submodule_property(

“auth”, “user_methods”, “AuthService”, client=lambda self: self

) room = make_submodule_property(

“room”, “room_methods”, “RoomMethods”, auth_client=lambda self: self.auth

)

zafiaonline.service_generator.helper.make_submodule_property(attr, module_name, class_name, **init_factories)[source]

Create a lazily-initialized submodule property.

This function returns a property object that, when accessed, imports a submodule dynamically, instantiates a target class, and injects required dependencies. The created instance is cached by the client to avoid repeated initialization.

Parameters:
  • attr (str) – Attribute name used as the cache key.

  • module_name (str) – Name of the submodule inside zafiaonline.api_client.

  • class_name (str) – Target class name within the submodule.

  • **init_factories (Callable) –

    Keyword arguments passed to the class constructor. Each value can be: - a callable (e.g., lambda self: self.auth) that will

    be evaluated with the client instance.

    • a static value passed directly.

Returns:

A property descriptor that lazily initializes and returns the requested submodule instance.

Return type:

property

Raises:
  • AttributeError – If a required dependency cannot be resolved (e.g., accessing a submodule before its dependency exists).

  • ImportError – If the requested submodule cannot be imported.

Module contents

zafiaonline.service_generator.make_submodule_property(attr, module_name, class_name, **init_factories)[source]

Create a lazily-initialized submodule property.

This function returns a property object that, when accessed, imports a submodule dynamically, instantiates a target class, and injects required dependencies. The created instance is cached by the client to avoid repeated initialization.

Parameters:
  • attr (str) – Attribute name used as the cache key.

  • module_name (str) – Name of the submodule inside zafiaonline.api_client.

  • class_name (str) – Target class name within the submodule.

  • **init_factories (Callable) –

    Keyword arguments passed to the class constructor. Each value can be: - a callable (e.g., lambda self: self.auth) that will

    be evaluated with the client instance.

    • a static value passed directly.

Returns:

A property descriptor that lazily initializes and returns the requested submodule instance.

Return type:

property

Raises:
  • AttributeError – If a required dependency cannot be resolved (e.g., accessing a submodule before its dependency exists).

  • ImportError – If the requested submodule cannot be imported.