MCPcopy
hub / github.com/treeverse/dvc / open

Function open

dvc/api/data.py:102–255  ·  view source on GitHub ↗

Opens a file tracked in a DVC project. This function may only be used as a context manager (using the `with` keyword, as shown in the examples). This function makes a direct connection to the remote storage, so the file contents can be streamed. Your code can process the data

(  # noqa: A001
    path: str,
    repo: Optional[str] = None,
    rev: Optional[str] = None,
    remote: Optional[str] = None,
    mode: str = "r",
    encoding: Optional[str] = None,
    config: Optional[dict[str, Any]] = None,
    remote_config: Optional[dict[str, Any]] = None,
)

Source from the content-addressed store, hash-verified

100
101
102def open( # noqa: A001
103 path: str,
104 repo: Optional[str] = None,
105 rev: Optional[str] = None,
106 remote: Optional[str] = None,
107 mode: str = "r",
108 encoding: Optional[str] = None,
109 config: Optional[dict[str, Any]] = None,
110 remote_config: Optional[dict[str, Any]] = None,
111):
112 """
113 Opens a file tracked in a DVC project.
114
115 This function may only be used as a context manager (using the `with`
116 keyword, as shown in the examples).
117
118 This function makes a direct connection to the remote storage, so the file
119 contents can be streamed. Your code can process the data buffer as it's
120 streamed, which optimizes memory usage.
121
122 Note:
123 Use dvc.api.read() to load the complete file contents
124 in a single function call, no context manager involved.
125 Neither function utilizes disc space.
126
127 Args:
128 path (str): location and file name of the target to open,
129 relative to the root of `repo`.
130 repo (str, optional): location of the DVC project or Git Repo.
131 Defaults to the current DVC project (found by walking up from the
132 current working directory tree).
133 It can be a URL or a file system path.
134 Both HTTP and SSH protocols are supported for online Git repos
135 (e.g. [user@]server:project.git).
136 rev (str, optional): Any `Git revision`_ such as a branch or tag name,
137 a commit hash or a dvc experiment name.
138 Defaults to HEAD.
139 If `repo` is not a Git repo, this option is ignored.
140 remote (str, optional): Name of the `DVC remote`_ used to form the
141 returned URL string.
142 Defaults to the `default remote`_ of `repo`.
143 For local projects, the cache is tried before the default remote.
144 mode (str, optional): Specifies the mode in which the file is opened.
145 Defaults to "r" (read).
146 Mirrors the namesake parameter in builtin `open()`_.
147 Only reading `mode` is supported.
148 encoding(str, optional): `Codec`_ used to decode the file contents.
149 Defaults to None.
150 This should only be used in text mode.
151 Mirrors the namesake parameter in builtin `open()`_.
152 config(dict, optional): config to be passed to the DVC repository.
153 Defaults to None.
154 remote_config(dict, optional): remote config to be passed to the DVC
155 repository.
156 Defaults to None.
157
158 Returns:
159 _OpenContextManager: A context manager that generatse a corresponding

Callers 15

initMethod · 0.85
_checkMethod · 0.85
_get_latest_versionMethod · 0.85
_spawnFunction · 0.85
sendFunction · 0.85
initFunction · 0.85
_write_imageMethod · 0.85
_btimeMethod · 0.85
logsMethod · 0.85
_pack_argsMethod · 0.85
_update_configMethod · 0.85
_update_git_configMethod · 0.85

Calls 1

_OpenContextManagerClass · 0.85

Tested by 15

testMethod · 0.68
extract_vega_specsFunction · 0.68
verify_imageFunction · 0.68
test_gc_skip_failedFunction · 0.68
test_cloud_cliFunction · 0.68
test_update_revFunction · 0.68
read_lock_fileFunction · 0.68
test_add_unicodeFunction · 0.68
test_run_no_execFunction · 0.68
test_repro_dry_no_execFunction · 0.68