Pyjulia
Pyjulia is a python module for calling julia functions inside your python code.
Usage
The julia interpreter is inside the PATH for the following examples. If you do not have julia inside your PATH you can also define the path to the julia interpreter like that:
import pyjulia
julia_module = pyjulia.Pyjulia("./example.jl")
julia_module.julia_interpreter = "your path to julia interpreter"
# execute code...
You will have to use the Fire package inside of your Julia code in order to use it like a cli application. An example would look like this:
using Fire
@main function add(num::Integer...)
println(sum(num))
end
@main function multiply(num::Integer...)
println(prod(num))
end
@main function greet(name, age, num::Integer...)
println(name, age)
println(num)
end
call_func method
Let's say the content of this julia code belongs to a file called example.jl. You can now call the add and multiply functions inside your python code:
import pyjulia
julia_module = pyjulia.Pyjulia("./example.jl")
my_args = [2, 3, 5]
julia_sum = julia_module.call_func("add", my_args)
julia_prod = julia_module.call_func("multiply", my_args)
print(julia_sum, julia_prod)
Your output should now look like this:
10 30
using dynamic function declaration
Let's use the same example.jl from before. This means the content will look like this:
using Fire
@main function add(num::Integer...)
println(sum(num))
end
@main function multiply(num::Integer...)
println(prod(num))
end
@main function greet(name, age, num::Integer...)
println(name, age)
println(num)
end
Now in order to call these function within your python code you need to do this:
⚠️ NOTE: Your IDE/text editor may tell you "Unresolved attribute reference add/multiply for class Julia". There's no need to worry. It should still work just as fine.
import pyjulia
julia_module = pyjulia.Pyjulia("./example.jl")
output = julia_module.add(my_args)
output2 = julia_module.multiply(my_args)
print(output, output2)
Your output should still look like this:
10 30
The greet function inside the julia file has multiple arguments. But this doesn't prevent us from calling it from python. It works just as fine as the other examples above:
import pyjulia
julia_module = pyjulia.Pyjulia("./example.jl")
greet_args = ["Pyjulia", 19, 2, 3, 4, 5]
greeting = julia_module.greet(greet_args)
print(greeting)
The following output should be printed to the terminal:
pyjulia 19
(2, 3, 4, 5)
You can just treat them as normal positional variables and the Fire package from julia will parse the arguments automatically.
Metadata
Release files for pyjulia 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyjulia-0.0.6.tar.gz | 7.5 kB | Without provenance | Details for pyjulia-0.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyjulia-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for pyjulia-0.0.6-py3-none-any.whl |
Total release size: 16.4 kB
Release files / pyjulia-0.0.6.tar.gz
| Download URL | pyjulia-0.0.6.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6deeae2c4fb500b088e4d7ad52db3c8296e9e50e1fa813afa64886f0a227305f
|
|
BLAKE2b-256 checksum How to use checksums |
e21a6ff3e3163cf166c97f8cc31addf389a846487f77f6dbcf35b8543c6f39b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.3
|
Release files / pyjulia-0.0.6-py3-none-any.whl
| Download URL | pyjulia-0.0.6-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a432a8e6ef565320e1cc991946bfe230f1f13b6571c1ec9e34494bd9415c8f2d
|
|
BLAKE2b-256 checksum How to use checksums |
49bb8dadd697f3403cb8cdbfb70fdd9da846cf66cf2c6891292c046a38ed96aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.3
|
Security for pyjulia 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.