Skip to content

HttpSessionMixin

Sub classes

Name Children Inherits
AsyncDataForSEOClient
searchly.providers.dataforseo_provider.dataforseo
Async client for DataForSEO API.
    AsyncJigsawStackClient
    searchly.providers.jigsawstack_provider.jigsawstack
    Async client for JigsawStack API.
      AsyncKagiClient
      searchly.providers.kagi_provider.client
      Async client for Kagi API.
        AsyncLinkUpClient
        searchly.providers.linkup_provider.client
        Async client for LinkUp API.
          AsyncSearch1API
          searchly.providers.search1_provider.client
          Async client for Search1API.
            AsyncSerpAPIClient
            searchly.providers.serpapi_provider.client
            Async client for SerpAPI.
              AsyncSerperClient
              searchly.providers.serper_provider.client
              Async client for Serper.dev API.
                AsyncYouClient
                searchly.providers.you_provider.you
                Async client for You.com API.

                  🛈 DocStrings

                  Gives a provider one anyenv.HttpSession, opened on first use.

                  A session's client belongs to the event loop it was opened on: on another loop (e.g. each anyenv.run_sync call) a new one is opened. Close it with aclose() or use the provider as async with provider: ... (else garbage collection drops its connections).

                  Source code in src/searchly/http.py
                  class HttpSessionMixin:
                      """Gives a provider one `anyenv.HttpSession`, opened on first use.
                  
                      A session's client belongs to the event loop it was opened on: on another loop
                      (e.g. each `anyenv.run_sync` call) a new one is opened. Close it with `aclose()`
                      or use the provider as `async with provider: ...` (else garbage collection
                      drops its connections).
                      """
                  
                      _http_session: anyenv.HttpSession | None = None
                  
                      async def _session(self) -> anyenv.HttpSession:
                          session = self._http_session
                          if session is None or not session.usable_here():
                              session = anyenv.HttpSession()
                              # Binds it to this loop; doesn't suspend, so concurrent first calls share it.
                              await session.__aenter__()
                              self._http_session = session
                          return session
                  
                      async def aclose(self) -> None:
                          """Close the HTTP session (its connections)."""
                          session, self._http_session = self._http_session, None
                          if session is not None and session.usable_here():
                              await session.aclose()
                  
                      async def __aenter__(self) -> Self:
                          return self
                  
                      async def __aexit__(self, *exc_info: object) -> None:
                          await self.aclose()
                  

                  aclose async

                  aclose() -> None
                  

                  Close the HTTP session (its connections).

                  Source code in src/searchly/http.py
                  async def aclose(self) -> None:
                      """Close the HTTP session (its connections)."""
                      session, self._http_session = self._http_session, None
                      if session is not None and session.usable_here():
                          await session.aclose()
                  

                  :fa-brands-github: Show source on GitHub