modal.Proxy
class Proxy(modal.object.Provider)
Proxy objects are used to setup secure tunnel connections to a private remote address, for example a database.
Currently modal.Proxy
objects must be setup with the assistance of Modal staff. If you require a proxy
please contact us.
def __init__(
self,
load: Callable[[Resolver, Optional[str]], Awaitable[H]],
rep: str,
is_persisted_ref: bool = False,
preload: Optional[Callable[[Resolver, Optional[str]], Awaitable[H]]] = None,
):
# TODO(erikbern): this is semi-deprecated - subclasses should use _from_loader
persist
@typechecked
def persist(self, label: str, namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE):
Deploy a Modal app containing this object. This object can then be imported from other apps using
the returned reference, or by calling modal.SharedVolume.from_name(label)
(or the equivalent method
on respective class).
Example Usage
import modal
volume = modal.SharedVolume().persist("my-volume")
stub = modal.Stub()
# Volume refers to the same object, even across instances of `stub`.
@stub.function(shared_volumes={"/vol": volume})
def f():
pass
from_name
@classmethod
def from_name(
cls: Type[P],
app_name: str,
tag: Optional[str] = None,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
) -> P:
Returns a reference to an Modal object of any type
Useful for referring to already created/deployed objects, e.g., Secrets
import modal
stub = modal.Stub()
@stub.function(secret=modal.Secret.from_name("my-secret-name"))
def some_function():
pass
lookup
@classmethod
def lookup(
cls: Type[P],
app_name: str,
tag: Optional[str] = None,
namespace=api_pb2.DEPLOYMENT_NAMESPACE_WORKSPACE,
client: Optional[_Client] = None,
) -> H:
General purpose method to retrieve Modal objects such as functions, shared volumes, and secrets.
import modal
square = modal.Function.lookup("my-shared-app", "square")
assert square(3) == 9
vol = modal.SharedVolume.lookup("my-shared-volume")
for chunk in vol.read_file("my_db_dump.csv"):
...