fxn 0.0.44__py3-none-any.whl → 0.0.45__py3-none-any.whl

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.
fxn/cli/__init__.py CHANGED
@@ -5,13 +5,15 @@
5
5
 
6
6
  import typer
7
7
 
8
+ from ..logging import TracebackMarkupConsole
9
+ from ..version import __version__
10
+
8
11
  from .auth import app as auth_app
9
12
  from .compile import compile_predictor
10
13
  from .misc import cli_options
11
14
  from .predictions import create_prediction
12
15
  from .predictors import archive_predictor, delete_predictor, retrieve_predictor
13
- from ..logging import TracebackMarkupConsole
14
- from ..version import __version__
16
+ from .sources import retrieve_source
15
17
 
16
18
  # Define CLI
17
19
  typer.main.console_stderr = TracebackMarkupConsole()
@@ -42,6 +44,7 @@ app.command(
42
44
  app.command(name="retrieve", help="Retrieve a predictor.")(retrieve_predictor)
43
45
  app.command(name="archive", help="Archive a predictor.")(archive_predictor)
44
46
  app.command(name="delete", help="Delete a predictor.")(delete_predictor)
47
+ app.command(name="source", help="Retrieve the native source code for a given prediction.")(retrieve_source)
45
48
 
46
49
  # Run
47
50
  if __name__ == "__main__":
fxn/cli/compile.py CHANGED
@@ -9,12 +9,12 @@ from inspect import getmembers, getmodulename, isfunction
9
9
  from pathlib import Path
10
10
  from pydantic import BaseModel
11
11
  from rich import print as print_rich
12
- from rich.progress import SpinnerColumn, TextColumn
13
12
  import sys
14
13
  from typer import Argument, Option
15
14
  from typing import Callable, Literal
16
15
  from urllib.parse import urlparse, urlunparse
17
16
 
17
+ from ..client import FunctionAPIError
18
18
  from ..compile import PredictorSpec
19
19
  from ..function import Function
20
20
  from ..sandbox import EntrypointCommand
@@ -25,11 +25,16 @@ class CompileError (Exception):
25
25
  pass
26
26
 
27
27
  def compile_predictor (
28
- path: str=Argument(..., help="Predictor path.")
28
+ path: str=Argument(..., help="Predictor path."),
29
+ overwrite: bool=Option(False, "--overwrite", help="Whether to delete any existing predictor with the same tag before compiling."),
29
30
  ):
30
- run_async(_compile_predictor_async(path))
31
+ run_async(_compile_predictor_async(path, overwrite=overwrite))
31
32
 
32
- async def _compile_predictor_async (path: str):
33
+ async def _compile_predictor_async (
34
+ path: str,
35
+ *,
36
+ overwrite: bool
37
+ ):
33
38
  fxn = Function(get_access_key())
34
39
  path: Path = Path(path).resolve()
35
40
  with CustomProgress():
@@ -47,6 +52,15 @@ async def _compile_predictor_async (path: str):
47
52
  # Compile
48
53
  with CustomProgressTask(loading_text="Running codegen...", done_text="Completed codegen"):
49
54
  with CustomProgressTask(loading_text="Creating predictor..."):
55
+ if overwrite:
56
+ try:
57
+ fxn.client.request(
58
+ method="DELETE",
59
+ path=f"/predictors/{spec.tag}"
60
+ )
61
+ except FunctionAPIError as error:
62
+ if error.status_code != 404:
63
+ raise
50
64
  predictor = fxn.client.request(
51
65
  method="POST",
52
66
  path="/predictors",
fxn/cli/sources.py ADDED
@@ -0,0 +1,46 @@
1
+ #
2
+ # Function
3
+ # Copyright © 2025 NatML Inc. All Rights Reserved.
4
+ #
5
+
6
+ from datetime import datetime
7
+ from pathlib import Path
8
+ from pydantic import BaseModel
9
+ from rich import print_json
10
+ from typer import Argument, Option
11
+ from typing_extensions import Annotated
12
+
13
+ from ..function import Function
14
+ from ..logging import CustomProgress, CustomProgressTask
15
+ from .auth import get_access_key
16
+
17
+ def retrieve_source (
18
+ predictor: Annotated[str, Option(help="Predictor tag.")] = None,
19
+ prediction: Annotated[str, Option(help="Prediction identifier. If specified, this MUST be from a prediction returned by the Function API.")] = None,
20
+ output: Annotated[Path, Option(help="Path to output source file.")] = Path("predictor.cpp")
21
+ ):
22
+ if not ((predictor is not None) ^ (prediction is not None)):
23
+ raise ValueError(f"Predictor tag or prediction identifier must be provided, but not both.")
24
+ fxn = Function(get_access_key())
25
+ with CustomProgress(transient=True):
26
+ if prediction is None:
27
+ with CustomProgressTask(loading_text="Creating prediction..."):
28
+ empty_prediction = fxn.predictions.create(tag=predictor)
29
+ prediction = empty_prediction.id
30
+ with CustomProgressTask(loading_text="Retrieving source..."):
31
+ source = fxn.client.request(
32
+ method="GET",
33
+ path=f"/predictions/{prediction}/source",
34
+ response_type=_PredictionSource
35
+ )
36
+ output.write_text(source.code)
37
+ source.code = str(output.resolve())
38
+ print_json(data=source.model_dump(mode="json", by_alias=True))
39
+
40
+ class _PredictionSource (BaseModel):
41
+ tag: str
42
+ target: str
43
+ code: str
44
+ created: datetime
45
+ compiled: datetime
46
+ latency: float # millis
fxn/compile.py CHANGED
@@ -23,7 +23,6 @@ class PredictorSpec (BaseModel):
23
23
  tag: str = Field(description="Predictor tag.")
24
24
  description: str = Field(description="Predictor description. MUST be less than 100 characters long.", min_length=4, max_length=100)
25
25
  sandbox: Sandbox = Field(description="Sandbox to compile the function.")
26
- trace_modules: list[ModuleType] = Field(description="Modules to trace and compile.", exclude=True)
27
26
  targets: list[str] | None = Field(description="Targets to compile this predictor for. Pass `None` to compile for our default targets.")
28
27
  access: AccessMode = Field(description="Predictor access.")
29
28
  card: str | None = Field(default=None, description="Predictor card (markdown).")
@@ -69,12 +68,12 @@ def compile (
69
68
  tag=tag,
70
69
  description=description,
71
70
  sandbox=sandbox if sandbox is not None else Sandbox(),
72
- trace_modules=trace_modules,
73
71
  targets=targets,
74
72
  access=access,
75
73
  card=card.read_text() if isinstance(card, Path) else card,
76
74
  media=None, # INCOMPLETE
77
75
  license=license,
76
+ trace_modules=trace_modules,
78
77
  **kwargs
79
78
  )
80
79
  # Wrap
fxn/version.py CHANGED
@@ -3,4 +3,4 @@
3
3
  # Copyright © 2025 NatML Inc. All Rights Reserved.
4
4
  #
5
5
 
6
- __version__ = "0.0.44"
6
+ __version__ = "0.0.45"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fxn
3
- Version: 0.0.44
3
+ Version: 0.0.45
4
4
  Summary: Run prediction functions locally in Python. Register at https://fxn.ai.
5
5
  Author-email: "NatML Inc." <hi@fxn.ai>
6
6
  License: Apache License
@@ -1,10 +1,10 @@
1
1
  fxn/__init__.py,sha256=eOYYoHwwQWzYVnyBO1VtcWR0JnUm1GPl4kr8IzhnCqg,257
2
2
  fxn/client.py,sha256=Deje8eiS1VOHX85tQnV34viv2CPVx2ljwHSbyVB5Z1o,3790
3
- fxn/compile.py,sha256=XO_0a0hEfM3SI03cb8EFs2xL6E6XpmrVtRPo2icR6J0,3529
3
+ fxn/compile.py,sha256=Z63DMk_pscerqf8uOgWYYEsEsJTDvfrfYBqKYk3PbKE,3426
4
4
  fxn/function.py,sha256=XeEuALkbVhkvwEBUfP0A2fu3tdimwHemoR17oomhzc8,1407
5
5
  fxn/logging.py,sha256=MsTSf0GZxrHNDwVAXDOh8_zRUg9hkeZ8DfhFUJs7D8A,7250
6
6
  fxn/sandbox.py,sha256=w2dnHMBaKOERxFMpeAP11X6_SPqcvnpd6SmX6b_FOYQ,7000
7
- fxn/version.py,sha256=zQOEiQse1Ff3n-mSuBrT9-JLRGel6n8RluZbXIshvHI,95
7
+ fxn/version.py,sha256=59sX9tjcjcy9gw0lAlJ18hN47PCe6nQlyoQ8YVYW0hM,95
8
8
  fxn/beta/__init__.py,sha256=gKoDhuXtXCjdhUYUqmF0gDPMhJfg3UwFgbvMtRB5ipo,111
9
9
  fxn/beta/client.py,sha256=0lfwQPcB9ToIJC7AcCXO6DlJKkmId8EChhd9bk29GGE,2611
10
10
  fxn/beta/prediction.py,sha256=9DTBahNF6m0TicLab2o9e8IKpiSV6K7cUSTYaFju0ZU,356
@@ -17,12 +17,13 @@ fxn/c/prediction.py,sha256=-d-5yreFAaRS-nDHzhfabRNtgYcmJGiY_N2dt09gk84,2689
17
17
  fxn/c/predictor.py,sha256=48poLj1AthzCgU9n6Wv9gL8o4gFucIlOnBO2wdor6r0,1925
18
18
  fxn/c/stream.py,sha256=Y1Xv1Bt3_qlnWg9rCn7NWESpouF1eKMzDiQjhZWbXTg,1105
19
19
  fxn/c/value.py,sha256=h5n91nm8C3YvEEFORfJBUdncZ29DFIdUKGWQ_KpLsWc,7420
20
- fxn/cli/__init__.py,sha256=OcdxY751a5avAWNYUpBG92kjqpKmYXwhZxgB1mGwUpA,1396
20
+ fxn/cli/__init__.py,sha256=vLCNLiXneZzMCFViDOngg3kQZ1rZwnZXzUSEOB38Il0,1542
21
21
  fxn/cli/auth.py,sha256=6iGbNbjxfCr8OZT3_neLThXdWeKRBZATwru8vU0XmRw,1688
22
- fxn/cli/compile.py,sha256=y5SOGSr5_B_WY-TYbg3Q9kCCaYGlbyQcDOYSPeg2lDc,5490
22
+ fxn/cli/compile.py,sha256=dd3IV1bhBCbMEo0Py6KGxn3vfv_TSDCLL2f-4qLzfiw,6037
23
23
  fxn/cli/misc.py,sha256=LcJbCj_GAgtGraTRva2zHHOPpNwI6SOFntRksxwlqvM,843
24
24
  fxn/cli/predictions.py,sha256=ma7wbsKD5CFCRTU_TtJ8N0nN1fgFX2BZPGG8qm8HlNI,3182
25
25
  fxn/cli/predictors.py,sha256=bVQAuBue_Jxb79X85RTCzOerWRRT2Ny1oF5DNYAsx4M,1545
26
+ fxn/cli/sources.py,sha256=HQ_PBLXY2CZ5tGuuqQeJQTpM9S9rKtBzyNVTK-ywG84,1781
26
27
  fxn/lib/__init__.py,sha256=-w1ikmmki5NMpzJjERW-O4SwOfBNkimej_0jL8ujYRk,71
27
28
  fxn/lib/linux/arm64/libFunction.so,sha256=NU9PEuQNObqtWPr5vXrWeQuYhzBfmX_Z4guaregFjrI,207632
28
29
  fxn/lib/linux/x86_64/libFunction.so,sha256=qZNlczayaaHIP_tJ9eeZ1TVpV1Os-ztvSWOoBuY9yWE,236272
@@ -39,9 +40,9 @@ fxn/types/dtype.py,sha256=71Tuu4IydmELcBcSBbmWswhCE-7WqBSQ4VkETsFRzjA,617
39
40
  fxn/types/prediction.py,sha256=BdLTxnKiSFbz5warX8g_Z4DedNxXK3gaNjSKR2FP8tA,2051
40
41
  fxn/types/predictor.py,sha256=KRGZEuDt7WPMCyRcZvQq4y2FMocfVrLEUNJCJgfDY9Y,4000
41
42
  fxn/types/user.py,sha256=Z44TwEocyxSrfKyzcNfmAXUrpX_Ry8fJ7MffSxRn4oU,1071
42
- fxn-0.0.44.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
43
- fxn-0.0.44.dist-info/METADATA,sha256=5o1xzi17jmhMTf14XKQHixi_msQz57j7oTx3DtjCQOg,16144
44
- fxn-0.0.44.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
45
- fxn-0.0.44.dist-info/entry_points.txt,sha256=O_AwD5dYaeB-YT1F9hPAPuDYCkw_W0tdNGYbc5RVR2k,45
46
- fxn-0.0.44.dist-info/top_level.txt,sha256=1ULIEGrnMlhId8nYAkjmRn9g3KEFuHKboq193SEKQkA,4
47
- fxn-0.0.44.dist-info/RECORD,,
43
+ fxn-0.0.45.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
44
+ fxn-0.0.45.dist-info/METADATA,sha256=5g5H7YpEWWAkji5HLSLajTb4npfo6igzAbNp6GQWjH4,16144
45
+ fxn-0.0.45.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
46
+ fxn-0.0.45.dist-info/entry_points.txt,sha256=O_AwD5dYaeB-YT1F9hPAPuDYCkw_W0tdNGYbc5RVR2k,45
47
+ fxn-0.0.45.dist-info/top_level.txt,sha256=1ULIEGrnMlhId8nYAkjmRn9g3KEFuHKboq193SEKQkA,4
48
+ fxn-0.0.45.dist-info/RECORD,,
File without changes