# ApifyEventManager<!-- -->

Event manager for the Apify platform.

This class extends Crawlee's `EventManager` to provide Apify-specific functionality, including websocket connectivity to the Apify platform for receiving platform events.

The event manager handles:

* Registration and emission of events and their listeners.
* Websocket connection to Apify platform events.
* Processing and validation of platform messages.
* Automatic event forwarding from the platform to local event listeners.

This class should not be used directly. Use the `Actor.on` and `Actor.off` methods to interact with the event system.

## Index[](#Index)

### Methods

* [\_\_aenter\_\_](https://docs.apify.com/sdk/python/reference/class/ApifyEventManager.md#__aenter__)
* [\_\_aexit\_\_](https://docs.apify.com/sdk/python/reference/class/ApifyEventManager.md#__aexit__)
* [\_\_init\_\_](https://docs.apify.com/sdk/python/reference/class/ApifyEventManager.md#__init__)
* [emit](https://docs.apify.com/sdk/python/reference/class/ApifyEventManager.md#emit)

## Methods<!-- -->[](#Methods)

### [](#__aenter__)[](https://github.com/apify/apify-sdk-python/blob/c674a4d42ade9c1a07f33062b6702497cd34b19d//src/apify/events/_apify_event_manager.py#L105)\_\_aenter\_\_

* async **\_\_aenter\_\_**(): Self

- Initialize the event manager upon entering the async context.

  On the outermost entry, it connects to the platform events websocket and starts consuming its messages.

  ***

  #### Returns Self

### [](#__aexit__)[](https://github.com/apify/apify-sdk-python/blob/c674a4d42ade9c1a07f33062b6702497cd34b19d//src/apify/events/_apify_event_manager.py#L141)\_\_aexit\_\_

* async **\_\_aexit\_\_**(exc_type, exc_value, exc_traceback): None

- Close the event manager upon exiting the async context.

  On the outermost exit, it stops consuming the platform messages and closes the websocket connection.

  ***

  #### Parameters

  * ##### exc_type: type\[BaseException] | None
  * ##### exc_value: BaseException | None
  * ##### exc_traceback: TracebackType | None

  #### Returns None

### [](#__init__)[](https://github.com/apify/apify-sdk-python/blob/c674a4d42ade9c1a07f33062b6702497cd34b19d//src/apify/events/_apify_event_manager.py#L76)\_\_init\_\_

* **\_\_init\_\_**(configuration): None

- Initialize a new instance.

  ***

  #### Parameters

  * ##### configuration: [Configuration](https://docs.apify.com/sdk/python/reference/class/Configuration.md)

    The Actor configuration for the event manager.

  #### Returns None

### [](#emit)[](https://github.com/apify/apify-sdk-python/blob/c674a4d42ade9c1a07f33062b6702497cd34b19d//src/apify/events/_apify_event_manager.py#L160)emit

* **emit**(\*, event, event_data): None

- #### Parameters

  * ##### keyword-onlyevent: Event
  * ##### keyword-onlyevent_data: EventData

  #### Returns None
