Skip to content

Commit bc42cb6

Browse files
committed
Add Image Details endpoint support
1 parent 7fca4bb commit bc42cb6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

roboflow/core/project.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,3 +767,37 @@ def __str__(self):
767767
json_str = {"name": self.name, "type": self.type, "workspace": self.__workspace}
768768

769769
return json.dumps(json_str, indent=2)
770+
771+
def image(self, image_id: str) -> Dict:
772+
"""
773+
Fetch the details of a specific image from the Roboflow API.
774+
775+
Args:
776+
image_id (str): The ID of the image to fetch.
777+
778+
Returns:
779+
Dict: A dictionary containing the image details.
780+
781+
Example:
782+
>>> import roboflow
783+
784+
>>> rf = roboflow.Roboflow(api_key="YOUR_API_KEY")
785+
786+
>>> project = rf.workspace().project("PROJECT_ID")
787+
788+
>>> image_details = project.image("image-id")
789+
"""
790+
url = f"{API_URL}/{self.__workspace}/{self.__project_name}/images/{image_id}" f"?api_key={self.__api_key}"
791+
792+
data = requests.get(url).json()
793+
794+
if "error" in data:
795+
raise RuntimeError(data["error"])
796+
797+
if "image" not in data:
798+
print(data, image_id)
799+
raise RuntimeError("Image not found")
800+
801+
image_details = data["image"]
802+
803+
return image_details

0 commit comments

Comments
 (0)