The ActorCore Python client provides a way to connect to and interact with actors from Python applications.

ActorCore is still pre-v1.0. Please help us by report bugs on GitHub Issues!

Quickstart

1

Create a new Python project

Create a new directory for your project:

mkdir my-app
cd my-app

It’s recommended to create a virtual environment:

python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate
2

Add dependencies

Install the ActorCore client package:

pip install actor-core-client
3

Define your actor

Create a file actors/app.ts in your project with your actor definition:

actors/app.ts
import { actor, setup } from "actor-core";

// Create actor
const counter = actor({
  state: { count: 0 },
  actions: {
    increment: (c, x: number) => {
  	c.state.count += x;
  	c.broadcast("newCount", c.state.count);
  	return c.state.count;
    }
  }
});

// Create the application
export const app = setup({
  actors: { counter },
  cors: { origin: "*" } // Configure CORS for your production domains in production
});

// Export app type for client usage
export type App = typeof app;
4

Create your client

Create a new file main.py:

import asyncio
from actor_core_client import AsyncClient

async def main():
    # Replace with your endpoint URL after deployment
    client = AsyncClient("http://localhost:6420")
    
    # Get or create an actor instance
    counter = await client.get("counter")
    
    # Subscribe to events using callback
    def on_new_count(msg):
        print(f"Event: {msg}")
        
    counter.on_event("newCount", on_new_count)
    
    # Call an action
    result = await counter.action("increment", 5)
    print(f"Action result: {result}")
    
    # Wait to receive events
    await asyncio.sleep(1)
    
    # Clean up
    await counter.disconnect()

if __name__ == "__main__":
    asyncio.run(main())

In the code above, subscription is done with on_event callbacks, but you can also subscribe directly with receive() calls, using the SimpleClient (and AsyncSimpleClient) interfaces. See our sample usage for more details.

5

Start your ActorCore development server

Launch the development server with:

npx @actor-core/cli@latest dev actors/app.ts

This will automatically start your app and open the studio in your browser. The studio supports hot-reloading, state inspection, visual RPC testing, and more debugging tools.

6

Run your client

In a separate terminal, run your Python code:

python main.py

You should see output like:

Event: 5
Action result: 5

Run it again to see the state update.

7

Deploy your ActorCore app

Now that you have your project running, deploy your application to one of these platforms:

Next Steps