Hi all, I’m creating a Pythonic resource to wrap a...
# ask-community
a
Hi all, I’m creating a Pythonic resource to wrap an API and I want to create a session object to be used for all calls in from the resource methods. I know from Pydantic that I can use
PrivateAttr()
to create private attributes and even have a default factory to populate them, eg:
Copy code
class MyResource(ConfigurableResource):
    api_key: str
    _session: ClientSession = PrivateAttr(default_factory=session_factory)
But what if I need one of the public attributes (eg.
api_key
) from the resource object to be used in the
session_factory
? This pattern won’t work, I’d need some sort of post init hook where I can set up
_session
before the instantiated resource itself is passed to the assets/ops. How should I do this?