Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 98a6361

Browse files
authored
Merge pull request #197 from iterative/api-reference-script
Api reference script
2 parents 0079da1 + 8d95062 commit 98a6361

21 files changed

+341
-214
lines changed

content/docs/api-reference/apply.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mlem.api.apply()
22

3-
Apply provided model against provided data
3+
Apply provided model against provided data.
44

55
```py
66
def apply(
@@ -9,8 +9,6 @@ def apply(
99
method: str = None,
1010
output: str = None,
1111
target_project: str = None,
12-
index: bool = None,
13-
external: bool = None,
1412
batch_size: Optional[int] = None,
1513
) -> Optional[Any]
1614
```
@@ -33,16 +31,19 @@ required.
3331

3432
## Parameters
3533

36-
- **`model`** (required) - MLEM model (a MlemModel object).
34+
- **`model`** (required) - MLEM model.
3735
- **`data`** (required) - Input to the model.
38-
- `method` (optional) - Which model method to use. If None, use the only method
39-
model has. If more than one is available, will fail.
40-
- `output` (optional) - If value is provided, assume its path and save output
36+
- `method` (optional) - Which model method to use.If None, use the only method
37+
model has.If more than one is available, will fail.
38+
- `output` (optional) - If value is provided,assume it's path and save output
4139
there.
42-
- `target_project` (optional) - The path to project to save the results to.
43-
- `index` (optional) - Whether to index saved output in MLEM root folder.
44-
- `external` (optional) - Whether to save result outside mlem dir.
45-
- `batch_size` (optional) - If data is to be loaded and applied in batches.
40+
- `target_project` (optional) - Path to MLEM project to save the result to.
41+
- `batch_size` (optional) - If provided, will process data in batches of given
42+
size.
43+
44+
## Returns
45+
46+
If `output=None`, returns results for given data. Otherwise returns None.
4647

4748
## Exceptions
4849

content/docs/api-reference/apply_remote.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mlem.api.apply_remote()
22

3-
Apply deployed model (possibly remote) against provided data.
3+
Apply provided model against provided data.
44

55
```py
66
def apply_remote(
@@ -9,7 +9,6 @@ def apply_remote(
99
method: str = None,
1010
output: str = None,
1111
target_project: str = None,
12-
index: bool = False,
1312
**client_kwargs,
1413
) -> Optional[Any]
1514
```
@@ -34,14 +33,16 @@ knows how to make requests to the deployed model.
3433

3534
- **`client`** (required) - The client to access methods of deployed model.
3635
- **`data`** (required) - Input to the model.
37-
- `method` (optional) - Which model method to use. If None, use the only method
38-
model has. If more than one is available, will fail.
39-
- `output` (optional) - If value is provided, assume its path and save output
36+
- **`method`** (required) - Which model method to use.If None, use the only
37+
method model has.If more than one is available, will fail.
38+
- `output` (optional) - If value is provided,assume it's path and save output
4039
there.
41-
- `target_project` (optional) - The path to project to save the results to.
42-
- `index` (optional) - Whether to index saved output in MLEM root folder.
43-
- `client_kwargs` (optional) - Keyword arguments for the underlying client
44-
implementation being used.
40+
- `target_project` (optional) - Path to MLEM project to save the result to.
41+
- `**client_kwargs` (optional) - Additional arguments to pass to client.
42+
43+
## Returns
44+
45+
If `output=None`, returns results for given data. Otherwise returns None.
4546

4647
## Exceptions
4748

content/docs/api-reference/build.md

+34-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# mlem.api.build()
22

3-
Build a [MLEM model](/doc/object-reference/mlem-abcs#modeltype) in pip-ready
4-
format, a built package using whl, docker-build-ready folder or directly build a
5-
docker image.
3+
Pack model into something useful, such as docker image, Python package or
4+
something else.
65

76
```py
87
def build(
@@ -27,33 +26,56 @@ This API is the underlying mechanism for the
2726
programmatically create ship-able assets from MlemModels such as pip-ready
2827
packages, Docker images, etc.
2928

30-
<admon type="tip">
29+
<details>
3130

32-
The arguments supplied to this method can be found with `mlem types`:
31+
### The arguments supplied to this method can be found with `mlem types` command
3332

3433
```cli
3534
$ mlem types builder pip
35+
Type mlem.contrib.pip.base.PipBuilder
36+
MlemABC parent type: builder
37+
MlemABC type: pip
38+
MlemObject type name: builder
39+
Create a directory python package
40+
Fields:
3641
[required] package_name: str
42+
Name of python package
3743
[required] target: str
38-
[not required] templates_dir: str = []
44+
Path to save result
45+
[not required] templates_dir: List[str] = []
46+
list of directories to look for jinja templates
47+
[not required] templates_dir.0: str = None
48+
Element of templates_dir
3949
[not required] python_version: str = None
50+
Required python version
4051
[not required] short_description: str = ""
52+
short_description
4153
[not required] url: str = ""
54+
url
4255
[not required] email: str = ""
56+
author's email
4357
[not required] author: str = ""
58+
author's name
4459
[not required] version: str = "0.0.0"
45-
[not required] additional_setup_kwargs: typing.Any = {}
60+
package version
61+
[not required] additional_setup_kwargs: Dict[str, any] = {}
62+
additional parameters for setup()
63+
[not required] additional_setup_kwargs.key: any = None
64+
Element of additional_setup_kwargs
4665
```
4766

48-
</admon>
67+
</details>
4968

5069
## Parameters
5170

52-
- **`builder`** (required) - Builder to use. Out-of-the-box supported string
53-
values are ['whl', 'pip', 'docker_dir', 'docker'].
71+
- **`builder`** (required) - Builder to use.
5472
- **`model`** (required) - The model to build.
55-
- `builder_kwargs` (optional) - Keyword arguments for the underlying builder
56-
being used.
73+
- **`builder_kwargs`** (required) - Additional keyword arguments to pass to the
74+
builder.
75+
76+
## Returns
77+
78+
The result of the build, different for different builders.
5779

5880
## Exceptions
5981

content/docs/api-reference/clone.md

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# mlem.api.clone()
22

3-
Clones MLEM object from `path` to `target` and returns Python representation for
4-
the created object.
3+
Clones [MLEM Object](/doc/user-guide/basic-concepts) from `path` to `out` and
4+
returns Python representation for the created object.
55

66
```py
77
def clone(
@@ -14,8 +14,6 @@ def clone(
1414
target_fs: Optional[str] = None,
1515
follow_links: bool = True,
1616
load_value: bool = False,
17-
index: bool = None,
18-
external: bool = None,
1917
) -> MlemObject
2018
```
2119

@@ -37,20 +35,21 @@ target.
3735
## Parameters
3836

3937
- **`path`** (required) - Path to the object. Could be local path or path inside
40-
a Git repo.
38+
a git repo.
4139
- **`target`** (required) - Path to save the copy of initial object to.
4240
- `project` (optional) - URL to project if object is located there.
43-
- `rev` (optional) - revision, could be Git commit SHA, branch name or tag.
41+
- `rev` (optional) - revision, could be git commit SHA, branch name or tag.
4442
- `fs` (optional) - filesystem to load object from
4543
- `target_project` (optional) - path to project to save cloned object to
4644
- `target_fs` (optional) - target filesystem
47-
- `follow_links` (optional) - If object we read is a MLEM link, whether to load
48-
the actual object link points to. Defaults to True.
49-
- `load_value` (optional) - Load actual Python object incorporated in MlemMeta
50-
object. Defaults to False.
51-
- `index` (optional) - Whether to index output in .mlem directory
52-
- `external` (optional) - whether to put object inside mlem dir in target
53-
project
45+
- `follow_links` (optional) - If object we read is a MLEM link, whether to
46+
loadthe actual object link points to. Defaults to True.
47+
- `load_value` (optional) - Load actual python object incorporated in
48+
MlemObject. Defaults to False.
49+
50+
## Returns
51+
52+
`MlemObject`: Copy of initial object saved to `out`.
5453

5554
## Exceptions
5655

content/docs/api-reference/deploy.md

+19-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
# mlem.api.deploy()
22

3-
Deploy a model to target environment. Can use existing deployment declaration or
4-
create a new one on-the-fly.
3+
Deploy a model to a target environment. Can use an existing deployment
4+
declaration or create a new one on-the-fly.
55

66
```py
77
def deploy(
8-
deploy_meta_or_path: Union[MlemDeploy, str],
9-
model: Union[MlemModel, str] = None,
8+
deploy_meta_or_path: Union[MlemDeployment, str],
9+
model: Union[MlemModel, str],
1010
env: Union[MlemEnv, str] = None,
1111
project: Optional[str] = None,
12+
rev: Optional[str] = None,
1213
fs: Optional[AbstractFileSystem] = None,
13-
external: bool = None,
14-
index: bool = None,
14+
env_kwargs: Dict[str, Any] = None,
1515
**deploy_kwargs,
16-
) -> MlemDeploy
16+
) -> MlemDeployment
1717
```
1818

19-
[//]: # '### Usage:'
20-
[//]: #
21-
[//]: # '```py'
22-
[//]: # 'from mlem.api import deploy'
23-
[//]: #
24-
[//]: # '#TODO'
25-
[//]: # '```'
26-
2719
## Description
2820

2921
This API is the underlying mechanism for the
@@ -32,17 +24,18 @@ provides a programmatic way to create deployments for a target environment.
3224

3325
## Parameters
3426

35-
- **`deploy_meta_or_path`** (required) - Path to deployment meta (will be
36-
created if it does not exist)
37-
- `model` (optional) - Path to model
38-
- `env` (optional) - Path to target environment
39-
- `project` (optional) - Path to MLEM project
40-
- `fs` (optional) - filesystem to load deploy meta from. If not provided, will
41-
be inferred from `deploy_meta_or_path`
42-
- `external` (optional) - Save result not in mlem dir, but directly in project
43-
- `index` (optional) - Whether to index output in .mlem directory
44-
- `deploy_kwargs` (optional) - Configuration for new deployment meta if it does
45-
not exist
27+
- **`deploy_meta_or_path`** (required) - MlemDeployment object or path to it.
28+
- **`model`** (required) - The model to deploy.
29+
- **`env`** (required) - The environment to deploy to.
30+
- `project` (optional) - Path to mlem project where to load obj from.
31+
- `rev` (optional) - Revision if object is stored in git repo.
32+
- `fs` (optional) - Filesystem to use to load the object.
33+
- `env_kwargs` (optional) - Additional kwargs to pass to the environment.
34+
- `deploy_kwargs` (optional) - Additional kwargs to pass to the deployment.
35+
36+
## Returns
37+
38+
`MlemDeployment`: The deployment object.
4639

4740
## Exceptions
4841

content/docs/api-reference/import_object.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# mlem.api.import_object()
22

3-
Try to load an object as MLEM model (or dataset) and return it, optionally
4-
saving to the specified target location.
3+
Try to load an object as MLEM model (or data) and return it, optionally saving
4+
to the specified target location.
55

66
```py
77
def import_object(
@@ -14,8 +14,6 @@ def import_object(
1414
target_fs: Optional[AbstractFileSystem] = None,
1515
type_: Optional[str] = None,
1616
copy_data: bool = True,
17-
external: bool = None,
18-
index: bool = None,
1917
)
2018
```
2119

@@ -47,19 +45,21 @@ command.
4745

4846
## Parameters
4947

50-
- **`path`** (required) - Path of file to import.
51-
- `project` (optional) - Path to MLEM project.
52-
- `rev` (optional) - revision, could be Git commit SHA, branch name or tag.
53-
- `fs` (optional) - FileSystem for the `path` argument
54-
- `target` (optional) - Path to save MLEM object into.
55-
- `target_project` (optional) - Path to MLEM project for `target`.
56-
- `target_fs` (optional) - FileSystem for the `target` argument
57-
- `type_` (optional) - Specify how to read file. Available types: ['pickle',
58-
'pandas']. Defaults to auto-infer.
59-
- `copy_data` (optional) - Whether to create a copy of file in target location
60-
or just link existing file. Defaults to True.
61-
- `external` (optional) - Save result directly to `target` (not inside `.mlem/`)
62-
- `index` (optional) - Whether to index output in `.mlem/` directory
48+
- **`path`** (required) - Path to the object to import.
49+
- `project` (optional) - Path to mlem project where to load obj from.
50+
- `rev` (optional) - Revision if object is stored in git repo.
51+
- `fs` (optional) - Filesystem to use to load the object.
52+
- `target` (optional) - Where to store the imported object.
53+
- `target_project` (optional) - If provided, treat `target` as object name and
54+
dumpobject in this MLEM Project.
55+
- `target_fs` (optional) - Filesystem to use to save the object.
56+
- `type_` (optional) - Type of the object to import. If not provided, will try
57+
toinfer from the object itself.
58+
- `copy_data` (optional) - Whether to copy data to the target location.
59+
60+
## Returns
61+
62+
`MlemObject`: Imported object.
6363

6464
## Exceptions
6565

content/docs/api-reference/init.md

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
# mlem.api.init()
22

3-
Creates `.mlem.yaml` config file in `path`. See
4-
[User Guide](/doc/user-guide/configuration) for more details.
3+
Creates [MLEM config](/doc/user-guide/configuration) in `path`.
54

65
```py
76
def init(path: str = ".") -> None
87
```
98

10-
### Usage:
11-
12-
```py
13-
from mlem.api import init
14-
15-
init(path)
16-
```
17-
189
## Description
1910

2011
Initializes a MLEM project by creating a new and empty `.mlem.yaml` file.
2112

2213
## Parameters
2314

24-
- **`path`** (required) - location of the target where a MLEM project has to be
25-
initialized i.e. a `.mlem/` folder has to be created. `.` by default
15+
- `path` (optional) - Path to create config in. Defaults to current directory.
16+
17+
## Returns
18+
19+
None
2620

2721
## Exceptions
2822

0 commit comments

Comments
 (0)