Python client for Phoenix channels, or alternatively, native websocket server for Phoenix?

How can I talk to Phoenix channels from a remote Python client?

I see this but it seems incomplete and I cannot get it to work.

I want to stream live data from an application that only has Python, C++ or Java clients. No javascript at all. I want to stream it into a phoenix server. How can I do this using channels since there is no native Python client. I see something from Supabase but docs all seem geared towards talking to their service.

Can someone point me to a complete example of Python talking to a Phoenix channel?

Alternative would be for Phoenix to expose a native websocket server without having to dig into Cowboy? Does this exist?

What are my options? Keep in mind must travel over http[s] as these is the only ports that are open.

Phoenix channels are a “custom” but transport agnostic protocol. They’re not “phoenix’s websocket implementation”. You can use websockets or long polling or any additional transport protocol you’d implement for talking to channels.

Phoenix does not implement websockets – just like it doesn’t handle http. Cowboy handles both of those concerns. Though I’m not sure what you’ve against integrating with cowboy. It’s a behaviour to implement with just a handful of callbacks: Nine Nines: cowboy_websocket(3)
From there you could use pubsub to talk to channels.

1 Like

The easiest way is to wrap the python client into a small CLI tool and let the elixir part talk to it via a port. You don’t need Phoenix Channels.

I fail to see why you can’t use the realtime library. You can definitely use it with a vanilla Phoenix application provided that you generate your sockets and channels. The only thing I would mention is that you’ll have to use Python 3.9.x, not 3.10.x as there’s an issue here: Python 3.10 support (loop parameter was removed from Lock()) · Issue #916 · aaugustin/websockets · GitHub

The documentation shows how you can connect to a locally hosted Phoenix application and I’ve tested it; it definitely works as intended.

1 Like

needs to go over http port 80 or 443 from behind a firewall. Don’t want to start port forwarding those as they’re needed by other appliations and ssh protocol almost certainly blocked anyway even on those ports.

I see thank you. I’ll take another look.

Elixir port is communicating via stdin/stdout.

http transport mandatory.

sorry for the pedantry, but personally I think thatt Phoenix easily exposes Cowboy’s http via routes and controllers etc in clean abstracted ways, whereas nothing analogous exists for websockets which for me is a bit of a surprise.

Probably we have some misunderstanding here. You said:

I want to stream live data from an application that only has Python, C++ or Java clients.

I took it as you have an existing application that you can access it via a python client. Now you want to access the same data from your Elixir application that you are building. So my suggestion is to wrap the python client with a small CLI tool and ship the small tool together with your elixir application. Since the CLI tool and the elixir application are running on the same machine, they can talk through port, right? Whatever means that the python client talks to the old application or how the elixir application is accessed from the outside are beside the point.

yeah unfortunately I should probably have specified earlier in the question that the client is remote, rather than pushing the http requirement to the end. Anyway that’s the way it its: has to be http.

I think I’ll try supabase’s realtime.py again. Thanks for the help.

it says it’s in alpha status, but maybe it’s a good starting point: GitHub - obmarg/chunnel: A python client for phoenix channels.

Also a list of clients Phoenix channels clients list | homesynck-server Java and CPP have a couple each to try I guess

1 Like

There’s also this: Raw Websockets in Phoenix - Binary Noggin

In case you don’t want to use the phx channel, but to roll your own protocol on top of raw websockets

1 Like

Would you mind providing the direct link to the document you are referring to?
I could not see how the link you provided show how we could connect to a locally hosted Phoenix app.

Thanks :slight_smile: