# Accessing Temporal Client from within Activity

**URL:** <https://community.temporal.io/t/accessing-temporal-client-from-within-activity/12941>\
**Category:** Community Support\
**Tags:** python-sdk\
**Created:** [July 24, 2024, 5:29am UTC](https://community.temporal.io/t/accessing-temporal-client-from-within-activity/12941 "2024-07-24T05:29:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kunal](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/kunal/32/4393_2.png) [@kunal](https://community.temporal.io/u/kunal)\
**Post date:** [July 24, 2024, 5:29am UTC](https://community.temporal.io/t/accessing-temporal-client-from-within-activity/12941/1 "2024-07-24T05:29:46Z")

</div>

I need to query the state of a workflow from within another workflow activity. I am using the workflow.query method but am running into issues provisioning the activity with a temporal client. How can I create or access the temporal client from within the activity?

I have tried duplicating the client manager structure from this link: [samples-python/hello/hello\_activity\_method.py at main · temporalio/samples-python · GitHub](https://github.com/temporalio/samples-python/blob/main/hello/hello_activity_method.py)  
but it either causes HTTP.client errors or isn’t able to access the initialized client from the worker.py file.

Are there any examples on how to provision an activity with the temporal client so that it can do a workflow query?

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [July 24, 2024, 12:05pm UTC](https://community.temporal.io/t/accessing-temporal-client-from-within-activity/12941/2 "2024-07-24T12:05:21Z")

</div>

> [@kunal](#):
>
> it either causes HTTP.client errors or isn’t able to access the initialized client from the worker.py file

Can you show your code or explain the failures better? You can take that example and replace the DB client with a Temporal client like so:

```python
class MyActivities:
    def __init__ (self, temporal_client: temporalio.client.Client) -> None:
        self.temporal_client = temporal_client

    @activity.defn
    async def start_workflow(self) -> None:
        await self.temporal_client.start_workflow(...)

```

---

<div class="post-metadata">

**Author:** ![kunal](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/kunal/32/4393_2.png) [@kunal](https://community.temporal.io/u/kunal)\
**Post date:** [July 24, 2024, 1:46pm UTC](https://community.temporal.io/t/accessing-temporal-client-from-within-activity/12941/3 "2024-07-24T13:46:50Z")

</div>

Yeah so that is what I did with the example, importing those activities into the workflow file once that was added triggered the HTTP.client passthrough error.

I can send a code snippet in a bit but what I ended up doing to resolve it for now is adding string names to the activity definition so that I don’t have to import the activities in the workflow file but can still reference them.

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [July 24, 2024, 2:05pm UTC](https://community.temporal.io/t/accessing-temporal-client-from-within-activity/12941/4 "2024-07-24T14:05:55Z")

</div>

Ah, yes, that sample doesn’t need to passthrough imports because it doesn’t use anything non-deterministic and it’s in the same file. But for most activity imports, they need to be passed through. You can look at other samples like [the langchain workflow](https://github.com/temporalio/samples-python/blob/main/langchain/workflow.py) to see how it does it.
