@@ -139,9 +139,82 @@ py_semaphore:current(). %% Currently executing
139139
140140See [ Scalability] ( scalability.md ) for details on execution modes and performance tuning.
141141
142+ ## Using from Elixir
143+
144+ erlang_python works seamlessly with Elixir. The ` :py ` module can be called directly:
145+
146+ ``` elixir
147+ # Start the application
148+ {:ok , _ } = Application .ensure_all_started (:erlang_python )
149+
150+ # Call Python functions
151+ {:ok , 4.0 } = :py .call (:math , :sqrt , [16 ])
152+
153+ # Evaluate expressions
154+ {:ok , result} = :py .eval (" 2 + 2" )
155+
156+ # With variables
157+ {:ok , 100 } = :py .eval (" x * y" , %{x: 10 , y: 10 })
158+
159+ # Call with keyword arguments
160+ {:ok , json} = :py .call (:json , :dumps , [%{name: " Elixir" }], %{indent: 2 })
161+ ```
162+
163+ ### Register Elixir Functions for Python
164+
165+ ``` elixir
166+ # Register an Elixir function
167+ :py .register_function (:factorial , fn [n] ->
168+ Enum .reduce (1 .. n, 1 , & */ 2 )
169+ end )
170+
171+ # Call from Python
172+ {:ok , 3628800 } = :py .eval (" __import__('erlang').call('factorial', 10)" )
173+
174+ # Cleanup
175+ :py .unregister_function (:factorial )
176+ ```
177+
178+ ### Parallel Processing with BEAM
179+
180+ ``` elixir
181+ # Register parallel map using BEAM processes
182+ :py .register_function (:parallel_map , fn [func_name, items] ->
183+ parent = self ()
184+
185+ refs = Enum .map (items, fn item ->
186+ ref = make_ref ()
187+ spawn (fn ->
188+ result = apply_function (func_name, item)
189+ send (parent, {ref, result})
190+ end )
191+ ref
192+ end )
193+
194+ Enum .map (refs, fn ref ->
195+ receive do
196+ {^ref , result} -> result
197+ after
198+ 5000 -> {:error , :timeout }
199+ end
200+ end )
201+ end )
202+ ```
203+
204+ ### Running the Elixir Example
205+
206+ A complete working example is available:
207+
208+ ``` bash
209+ elixir --erl " -pa _build/default/lib/erlang_python/ebin" examples/elixir_example.exs
210+ ```
211+
212+ This demonstrates basic calls, data conversion, callbacks, parallel processing (10x speedup), and AI integration.
213+
142214## Next Steps
143215
144216- See [ Type Conversion] ( type-conversion.md ) for detailed type mapping
145217- See [ Streaming] ( streaming.md ) for working with generators
146218- See [ Memory Management] ( memory.md ) for GC and debugging
147219- See [ Scalability] ( scalability.md ) for parallelism and performance
220+ - See [ AI Integration] ( ai-integration.md ) for ML/AI examples
0 commit comments