Skip to content

Commit 8258dbb

Browse files
authored
feat: add --api-key parameter to unstructured-ingest (#644)
1 parent 9443bd4 commit 8258dbb

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

Diff for: CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
## 0.7.5-dev1
1+
## 0.7.5-dev2
22

33
### Enhancements
44

55
* Adds functionality to sort elements in `partition_pdf` for `fast` strategy
66
* Adds ingest tests with `--fast` strategy on PDF documents
7+
* Adds --api-key to unstructured-ingest
8+
79

810
### Features
911

Diff for: unstructured/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.7.5-dev1" # pragma: no cover
1+
__version__ = "0.7.5-dev2" # pragma: no cover

Diff for: unstructured/ingest/interfaces.py

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class StandardConnectorConfig:
2929
metadata_include: Optional[str] = None
3030
partition_by_api: bool = False
3131
partition_endpoint: str = "https://api.unstructured.io/general/v0/general"
32+
api_key: str = ""
3233
preserve_downloads: bool = False
3334
re_download: bool = False
3435

@@ -179,9 +180,13 @@ def partition_file(self, **partition_kwargs) -> List[Dict[str, Any]]:
179180
logger.debug(f"Using remote partition ({endpoint})")
180181

181182
with open(self.filename, "rb") as f:
183+
headers_dict = {}
184+
if len(self.standard_config.api_key) > 0:
185+
headers_dict["UNSTRUCTURED-API-KEY"] = self.standard_config.api_key
182186
response = requests.post(
183187
f"{endpoint}",
184188
files={"files": (str(self.filename), f)},
189+
headers=headers_dict,
185190
# TODO: add m_data_source_metadata to unstructured-api pipeline_api and then
186191
# pass the stringified json here
187192
)

Diff for: unstructured/ingest/main.py

+7
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ def run(self):
151151
help="The method that will be used to process the documents. "
152152
"Default: auto. Other strategies include `fast` and `hi_res`.",
153153
)
154+
@click.option(
155+
"--api-key",
156+
default="",
157+
help="API Key for partition endpoint.",
158+
)
154159
@click.option(
155160
"--local-input-path",
156161
default=None,
@@ -443,6 +448,7 @@ def main(
443448
partition_by_api,
444449
partition_endpoint,
445450
partition_strategy,
451+
api_key,
446452
local_input_path,
447453
local_recursive,
448454
local_file_glob,
@@ -545,6 +551,7 @@ def main(
545551
partition_endpoint=partition_endpoint,
546552
preserve_downloads=preserve_downloads,
547553
re_download=re_download,
554+
api_key=api_key,
548555
)
549556
if remote_url:
550557
protocol = urlparse(remote_url).scheme

0 commit comments

Comments
 (0)