rubyx-py 0.1.1-x86_64-linux → 0.2.0-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +38 -24
- data/docs/assets/logo.png +0 -0
- data/lib/rubyx/3.1/rubyx.so +0 -0
- data/lib/rubyx/3.2/rubyx.so +0 -0
- data/lib/rubyx/3.3/rubyx.so +0 -0
- data/lib/rubyx/3.4/rubyx.so +0 -0
- data/lib/rubyx/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b8951867f0b79a0a42332ed2ab96c8473847d306f056f50216a791e9c7455ea8
|
|
4
|
+
data.tar.gz: 108ff5e86840e1c1f6162bdf1c35a5bde636ec66d5bcbe884f562c15487ec91e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ad0bc5de37ee7224751a605ce524b44e655a0c20a0683c3a410f8988d9b7259a7df47543de2669aa11ebc844e35e551f47da9c1177c2abdca32753caae5f197
|
|
7
|
+
data.tar.gz: 34adc99306f4b9b191a618fdf73da224d39ccf948a91b725600fac1c802639412da459609bb0cee392d73657966c5b930924f915d63bb9fcca9c3cbf2215d103
|
data/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
+
<img src="docs/assets/logo.png" alt="rubyx-py" width="200">
|
|
4
|
+
|
|
3
5
|
# Rubyx-py
|
|
4
6
|
|
|
5
7
|
**Call Python from Ruby. No microservices, no REST APIs, no serialization overhead.**
|
|
6
8
|
|
|
7
9
|
Powered by Rust for safety and performance. Built for Rails.
|
|
8
10
|
|
|
9
|
-
[](https://badge.fury.io/rb/rubyx)
|
|
11
|
+
[](https://badge.fury.io/rb/rubyx-py)
|
|
10
12
|
[](https://github.com/yinho999/rubyx/actions/workflows/ci.yml)
|
|
11
13
|
[](https://opensource.org/licenses/MIT)
|
|
12
14
|
[](https://www.ruby-lang.org)
|
|
@@ -34,15 +36,17 @@ Rubyx.stream(llm.generate("Tell me about Ruby")).each { |token| print token }
|
|
|
34
36
|
# Non-blocking — Ruby stays free while Python works
|
|
35
37
|
future = Rubyx.async_await("model.predict(data)", data: [1, 2, 3])
|
|
36
38
|
do_other_work()
|
|
37
|
-
result = future.
|
|
39
|
+
result = future.await # GVL released during wait, reacquired when ready
|
|
38
40
|
```
|
|
39
41
|
|
|
40
42
|
### Built with non-blocking in mind
|
|
41
43
|
|
|
42
44
|
- **`Rubyx.stream`** / **`Rubyx.nb_stream`** — release Ruby's GVL during iteration, other threads and Fibers keep
|
|
43
45
|
running
|
|
44
|
-
- **`Rubyx.async_await`** — spawns Python on background threads, returns a `Future` immediately
|
|
45
|
-
|
|
46
|
+
- **`Rubyx.async_await`** — spawns Python on background threads, returns a `Future` immediately; `future.await` releases
|
|
47
|
+
the GVL while waiting, reacquires when ready
|
|
48
|
+
- **`Rubyx.await`** — GVL released while waiting; returns native Ruby types for primitives, `RubyxObject` for complex
|
|
49
|
+
Python objects
|
|
46
50
|
|
|
47
51
|
Ideal for LLM streaming, ML inference, data pipelines, and high-concurrency Rails apps.
|
|
48
52
|
|
|
@@ -88,20 +92,27 @@ dependencies = []
|
|
|
88
92
|
### 1. Sync — call a Python function
|
|
89
93
|
|
|
90
94
|
```python
|
|
91
|
-
# app/python/
|
|
92
|
-
def
|
|
93
|
-
return f"Hello, {name}!"
|
|
95
|
+
# app/python/example.py
|
|
96
|
+
def hello(name="World"):
|
|
97
|
+
return f"Hello, {name}! From Python."
|
|
94
98
|
```
|
|
95
99
|
|
|
96
100
|
```ruby
|
|
101
|
+
|
|
97
102
|
class GreetingsController < ApplicationController
|
|
98
|
-
def
|
|
99
|
-
|
|
100
|
-
render json: { message: hello
|
|
103
|
+
def index
|
|
104
|
+
example = Rubyx.import('example')
|
|
105
|
+
render json: { message: example.hello(params[:name]).to_ruby }
|
|
101
106
|
end
|
|
102
107
|
end
|
|
103
108
|
```
|
|
104
109
|
|
|
110
|
+
```ruby
|
|
111
|
+
Rails.application.routes.draw do
|
|
112
|
+
root "greetings#index"
|
|
113
|
+
end
|
|
114
|
+
```
|
|
115
|
+
|
|
105
116
|
### 2. Streaming — iterate a Python generator
|
|
106
117
|
|
|
107
118
|
```python
|
|
@@ -112,6 +123,7 @@ def count_up(n):
|
|
|
112
123
|
```
|
|
113
124
|
|
|
114
125
|
```ruby
|
|
126
|
+
|
|
115
127
|
class CountController < ApplicationController
|
|
116
128
|
include ActionController::Live
|
|
117
129
|
|
|
@@ -141,6 +153,7 @@ async def delayed_greet(name, seconds=1):
|
|
|
141
153
|
```
|
|
142
154
|
|
|
143
155
|
```ruby
|
|
156
|
+
|
|
144
157
|
class TasksController < ApplicationController
|
|
145
158
|
def show
|
|
146
159
|
tasks = Rubyx.import('tasks')
|
|
@@ -148,7 +161,7 @@ class TasksController < ApplicationController
|
|
|
148
161
|
# Non-blocking — returns a Future immediately
|
|
149
162
|
future = Rubyx.async_await(tasks.delayed_greet(params[:name], seconds: 2))
|
|
150
163
|
do_other_work()
|
|
151
|
-
render json: { message: future.
|
|
164
|
+
render json: { message: future.await.to_ruby }
|
|
152
165
|
end
|
|
153
166
|
end
|
|
154
167
|
```
|
|
@@ -263,6 +276,7 @@ end
|
|
|
263
276
|
```
|
|
264
277
|
|
|
265
278
|
```ruby
|
|
279
|
+
|
|
266
280
|
class ChatController < ApplicationController
|
|
267
281
|
include ActionController::Live
|
|
268
282
|
|
|
@@ -378,13 +392,13 @@ ctx = Rubyx.context
|
|
|
378
392
|
ctx.eval("import asyncio")
|
|
379
393
|
ctx.eval("async def fetch(url): ...")
|
|
380
394
|
|
|
381
|
-
#
|
|
395
|
+
# GVL released while waiting, reacquired when ready
|
|
382
396
|
result = ctx.await("fetch(url)", url: "https://example.com")
|
|
383
397
|
|
|
384
398
|
# Non-blocking (returns Future)
|
|
385
399
|
future = ctx.async_await("fetch(url)", url: "https://example.com")
|
|
386
400
|
do_other_stuff()
|
|
387
|
-
result = future.
|
|
401
|
+
result = future.await # GVL released during wait, reacquired when ready
|
|
388
402
|
future.ready? # check without blocking
|
|
389
403
|
```
|
|
390
404
|
|
|
@@ -433,17 +447,17 @@ svc.Analyzer([1, 2, 3]).summary.to_ruby # => {"count" => 3, "sum" => 6}
|
|
|
433
447
|
|
|
434
448
|
## API Reference
|
|
435
449
|
|
|
436
|
-
| Method | Description
|
|
437
|
-
|
|
438
|
-
| `Rubyx.uv_init(toml, **opts)` | Setup Python env and initialize
|
|
439
|
-
| `Rubyx.import(name)` | Import a Python module
|
|
440
|
-
| `Rubyx.eval(code, **globals)` | Evaluate Python code
|
|
441
|
-
| `Rubyx.await(code, **globals)` | Run async code (
|
|
442
|
-
| `Rubyx.async_await(code, **globals)` | Run async code (returns Future) |
|
|
443
|
-
| `Rubyx.stream(iterable)` | Stream a Python generator
|
|
444
|
-
| `Rubyx.nb_stream(iterable)` | Non-blocking stream (GVL-aware)
|
|
445
|
-
| `Rubyx.context` | Create isolated Python context
|
|
446
|
-
| `Rubyx.initialized?` | Check if Python is ready
|
|
450
|
+
| Method | Description |
|
|
451
|
+
|--------------------------------------|-----------------------------------------------|
|
|
452
|
+
| `Rubyx.uv_init(toml, **opts)` | Setup Python env and initialize |
|
|
453
|
+
| `Rubyx.import(name)` | Import a Python module |
|
|
454
|
+
| `Rubyx.eval(code, **globals)` | Evaluate Python code |
|
|
455
|
+
| `Rubyx.await(code, **globals)` | Run async code (GVL released while waiting) |
|
|
456
|
+
| `Rubyx.async_await(code, **globals)` | Run async code (non-blocking, returns Future) |
|
|
457
|
+
| `Rubyx.stream(iterable)` | Stream a Python generator |
|
|
458
|
+
| `Rubyx.nb_stream(iterable)` | Non-blocking stream (GVL-aware) |
|
|
459
|
+
| `Rubyx.context` | Create isolated Python context |
|
|
460
|
+
| `Rubyx.initialized?` | Check if Python is ready |
|
|
447
461
|
|
|
448
462
|
| RubyxObject | |
|
|
449
463
|
|--------------------------|-------------------------------|
|
|
Binary file
|
data/lib/rubyx/3.1/rubyx.so
CHANGED
|
Binary file
|
data/lib/rubyx/3.2/rubyx.so
CHANGED
|
Binary file
|
data/lib/rubyx/3.3/rubyx.so
CHANGED
|
Binary file
|
data/lib/rubyx/3.4/rubyx.so
CHANGED
|
Binary file
|
data/lib/rubyx/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubyx-py
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: x86_64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Naiker
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-03-
|
|
11
|
+
date: 2026-03-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake-compiler
|
|
@@ -47,6 +47,7 @@ extensions: []
|
|
|
47
47
|
extra_rdoc_files: []
|
|
48
48
|
files:
|
|
49
49
|
- README.md
|
|
50
|
+
- docs/assets/logo.png
|
|
50
51
|
- ext/rubyx/src/python/sync_adapter.py
|
|
51
52
|
- lib/generators/rubyx/install_generator.rb
|
|
52
53
|
- lib/generators/rubyx/templates/example.py
|