- 
                Notifications
    You must be signed in to change notification settings 
- Fork 56
Closed
Description
Currently, only the command line can use the STAC_URL environment variable for automatically discovering the STAC endpoint. It'd be nice to use it with the Python Client class as well.
This should do the trick, however I don't have a good idea how to test it. Anyone have thoughts?
diff --git a/pystac_client/client.py b/pystac_client/client.py
index 0fc03c6..c8e684b 100644
--- a/pystac_client/client.py
+++ b/pystac_client/client.py
@@ -75,13 +75,13 @@ class Client(pystac.Catalog, STACAPIObjectMixin):
         return '<Catalog id={}>'.format(self.id)
 
     @classmethod
-    def open(cls, url, headers=None):
+    def open(cls, url=None, headers=None):
         """Alias for PySTAC's STAC Object `from_file` method
 
         Parameters
         ----------
-        url : str
-            The URL of a STAC Catalog
+        url : str, optional
+            The URL of a STAC Catalog. If not specified, this will use the `STAC_URL` environment variable.
 
         Returns
         -------
@@ -89,6 +89,12 @@ class Client(pystac.Catalog, STACAPIObjectMixin):
         """
         import pystac_client.stac_io
 
+        if url is None:
+            url = os.environ.get("STAC_URL")
+
+        if url is None:
+            raise TypeError("'url' must be specified or the 'STAC_URL' environment variable must be set.")
+
         def read_text_method(url):
             request = Request(url, headers=headers or {})
             return pystac_client.stac_io.read_text_method(request)Metadata
Metadata
Assignees
Labels
No labels