Planet-scale distributed computing in Python.
!!! RESEARCH PREVIEW !!!
Pythagoras is a super-scalable, easy-to-use, and low-maintenance framework for (1) massive algorithm parallelization and (2) hardware usage optimization in Python. It simplifies and speeds up data science, machine learning, and AI workflows.
Pythagoras excels at complex, long-running, resource-demanding computations. It’s not recommended for real-time, latency-sensitive workflows.
Pythagoras elevates two popular techniques — memoization and parallelization — to a global scale and then fuses them, unlocking performance and scalability that were previously out of reach.
Drawing from many years of functional-programming practice, Pythagoras extends these proven ideas to the next level. In a Pythagoras environment, you can seamlessly employ your preferred functional patterns, augmented by new capabilities.
!!! BOOKMARK THIS PAGE AND COME BACK LATER, WE WILL PUBLISH MORE TUTORIALS SOON !!!
Importing Pythagoras:
from pythagoras.core import *
import pythagoras as pth
Creating a portal based on a (shared) folder:
my_portal = get_portal("./my_local_folder")
Checking the state of a portal:
my_portal.describe()
Decorating a function:
@pure()
def my_long_running_function(a:float, b:float) -> float:
from time import sleep # imports must be placed inside a pure function
sleep(5)
return a+10*b
Using a decorated function synchronously:
result = my_long_running_function(a=1, b=2) # only named arguments are allowed
Using a decorated function asynchronously:
future_result_address = my_long_running_function.swarm(a=10, b=20)
if ready(future_result_address):
result = get(future_result_address)
Pre-conditions for executing a function:
@pure(pre_validators=[
unused_ram(Gb=5),
installed_packages("scikit-learn","pandas"),
unused_cpu(cores=10)])
def my_long_running_function(a:float, b:float) -> float:
from time import sleep
sleep(5)
return a+10*b
Recursion:
@pure(pre_validators=[recursive_parameters("n")])
def factorial(n:int)->int:
if n == 1:
return 1
else:
return n*factorial(n=n-1) # only named arguments are allowed
Partial function application:
@pure()
def my_map(input_list:list, transformer: PureFn)->list:
result = []
for element in input_list:
transformed_element = transformer(x=element)
result.append(transformed_element)
return result
@pure()
def my_square(x):
return x*x
result = my_map(input_list=[1,2,3,4,5], transformer=my_square)
my_square_map = my_map.fix_kwargs(transformer = my_square)
result = my_square_map(input_list=[1,2,3,4,5])
Mutually recursive functions:
@pure(pre_validators=recursive_parameters("n"))
def is_even(n:int, is_odd ,is_even)->bool:
if n in {0,2}:
return True
else:
return is_odd(n=n-1, is_even=is_even, is_odd=is_odd)
@pure(pre_validators=recursive_parameters("n"))
def is_odd(n:int, is_even, is_odd)->bool:
if n in {0,2}:
return False
else:
return is_even(n=n-1, is_odd=is_odd, is_even=is_even)
(is_even, is_odd) = (
is_even.fix_kwargs(is_odd=is_odd, is_even=is_even)
, is_odd.fix_kwargs(is_odd=is_odd, is_even=is_even) )
assert is_even(n=10)
assert is_odd(n=11)
The source code is hosted on GitHub at: https://github.com/pythagoras-dev/pythagoras
Installers for the latest released version are available at the Python package index at: https://pypi.org/project/pythagoras
Using uv :
uv add pythagoras
Using pip (legacy alternative to uv):
pip install pythagoras
- persidict
- parameterizable
- jsonpickle
- joblib
- lz4
- pandas
- numpy
- psutil
- boto3
- pytest
- moto
- boto3
- scipy
- jsonpickle
- scikit-learn
- autopep8
- deepdiff
- nvidia-ml-p
- uv
Pythagoras of Samos was a famous ancient Greek thinker and scientist who was the first man to call himself a philosopher ("lover of wisdom"). He is most recognised for his many mathematical findings, including the Pythagorean theorem.
Not everyone knows that in antiquity, Pythagoras was also credited with major astronomical discoveries, such as sphericity of the Earth and the identity of the morning and evening stars as the planet Venus.