Source: dvc/api/data.py:28-90
Description
Returns the URL to the storage location of a data file or directory tracked in a DVC repository. This function provides direct access to the remote storage URL without downloading the file. For Git repositories,HEAD is used unless a rev argument is supplied. The default remote is tried unless a remote argument is supplied.
Signature
Parameters
str
required
Location and filename of the target, relative to the root of the repository.
str
default:"None"
Location of the DVC project or Git repository. Defaults to the current DVC project (found by walking up from the current working directory).Can be:
- A URL to a Git repository
- A local file system path
- Both HTTP and SSH protocols are supported for online Git repos
str
default:"None"
Any Git revision such as a branch or tag name, a commit hash, or a DVC experiment name.
- Defaults to
HEADfor Git repositories - If
repois not a Git repo, this option is ignored
str
default:"None"
Name of the DVC remote used to form the returned URL string.
- Defaults to the default remote of the repository
- For local projects, the cache is tried before the default remote
dict
default:"None"
Config dictionary to be passed to the DVC repository.
dict
default:"None"
Remote config dictionary to be passed to the DVC repository.
Returns
str
The URL to the file or directory in remote storage. The format depends on the remote type:
- S3:
s3://bucket-name/path/to/file - GCS:
gs://bucket-name/path/to/file - Azure:
azure://container/path/to/file - HTTP:
https://server.com/path/to/file - SSH:
ssh://user@server/path/to/file - Local:
file:///path/to/file
Raises
exception
Raised when the file is not tracked by DVC.
exception
Raised when no remote is configured or specified.
exception
Raised when accessing an external repository with no remote configured.
Examples
Basic Usage
Get URL from Specific Remote
Access Different Versions
Download with External Tool
Use with AWS CLI
Check Multiple Files
Get Directory URL
From Specific Tag
Error Handling
Custom Remote Configuration
Generate Presigned URL (S3)
Use Cases
Direct Downloads
Download files using external tools like wget, curl, or AWS CLI.
URL Sharing
Share direct URLs to data with team members or services.
Integration
Integrate DVC-tracked data with other tools and services.
Presigned URLs
Generate temporary access URLs for private cloud storage.
Remote Storage URL Formats
- S3
- Google Cloud Storage
- Azure Blob
- HTTP/HTTPS
- SSH
Important Notes
Cache Priority: For local projects, DVC will try to get the URL from the local cache before checking the default remote.
Best Practices
Verify file existence
Verify file existence
Since
get_url() doesn’t check if the file exists, verify before using:Use for large files
Use for large files
For very large files, getting the URL allows you to use optimized download tools:
Handle different storage types
Handle different storage types
Parse URLs appropriately based on storage type:
Consider authentication
Consider authentication
Remember that accessing the URL may require authentication:
Comparison with Other Functions
Related Functions
read()
Read complete file contents
open()
Stream file with context manager
DVCFileSystem
File system interface