Skip to content

Commit 14153bf

Browse files
authored
Merge pull request #1 from Zipstack/pypi-publish
Refactoring and PDM Integration
2 parents 4032111 + dc0a04b commit 14153bf

File tree

11 files changed

+1186
-27
lines changed

11 files changed

+1186
-27
lines changed

.github/workflows/main.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Publish Python Package
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
pypi-publish:
10+
name: upload release to PyPI
11+
runs-on: ubuntu-20.04
12+
permissions:
13+
contents: read
14+
id-token: write
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
ref: ${{ github.event.release.tag_name }}
19+
20+
- name: Setup PDM
21+
uses: pdm-project/setup-pdm@v4
22+
with:
23+
python-version: 3.11
24+
version: 2.10.0
25+
26+
- name: Publish package distributions to PyPI
27+
run: pdm publish

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,4 @@ cython_debug/
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162162
#.idea/
163+
tests/data/*

.pre-commit-config.yaml

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
# See https://pre-commit.com for more information
3+
# See https://pre-commit.com/hooks.html for more hooks
4+
# - Added pkgs feature flag auto generated code to flake8 exclude list
5+
# Force all unspecified python hooks to run python 3.10
6+
default_language_version:
7+
python: python3.9
8+
default_stages:
9+
- commit
10+
repos:
11+
- repo: https://github.com/pre-commit/pre-commit-hooks
12+
rev: v4.5.0
13+
hooks:
14+
- id: trailing-whitespace
15+
# TODO: Exclude tests/test_data directory
16+
exclude: ^tests/test_data/
17+
exclude_types:
18+
- "markdown"
19+
- id: end-of-file-fixer
20+
- id: check-yaml
21+
args: [--unsafe]
22+
- id: check-added-large-files
23+
args: ["--maxkb=10240"]
24+
- id: check-case-conflict
25+
- id: check-docstring-first
26+
- id: check-ast
27+
- id: check-json
28+
exclude: ".vscode/launch.json"
29+
- id: check-executables-have-shebangs
30+
- id: check-shebang-scripts-are-executable
31+
- id: check-toml
32+
- id: debug-statements
33+
- id: detect-private-key
34+
- id: check-merge-conflict
35+
- id: check-symlinks
36+
- id: destroyed-symlinks
37+
- id: forbid-new-submodules
38+
- id: mixed-line-ending
39+
- id: no-commit-to-branch
40+
- repo: https://github.com/adrienverge/yamllint
41+
rev: v1.35.1
42+
hooks:
43+
- id: yamllint
44+
args: ["-d", "relaxed"]
45+
language: system
46+
- repo: https://github.com/rhysd/actionlint
47+
rev: v1.6.26
48+
hooks:
49+
- id: actionlint-docker
50+
args: [-ignore, 'label ".+" is unknown']
51+
- repo: https://github.com/psf/black
52+
rev: 24.2.0
53+
hooks:
54+
- id: black
55+
args: [--config=pyproject.toml, -l 120]
56+
language: system
57+
exclude: |
58+
(?x)^(
59+
pkgs/unstract-flags/src/unstract/flags/evaluation_.*\.py|
60+
)$
61+
- repo: https://github.com/pycqa/flake8
62+
rev: 7.0.0
63+
hooks:
64+
- id: flake8
65+
args: [--max-line-length=120]
66+
exclude: |
67+
(?x)^(
68+
.*migrations/.*\.py|
69+
unstract-core/tests/.*|
70+
pkgs/unstract-flags/src/unstract/flags/evaluation_.*\.py|
71+
)$
72+
- repo: https://github.com/pycqa/isort
73+
rev: 5.13.2
74+
hooks:
75+
- id: isort
76+
files: "\\.(py)$"
77+
args:
78+
[
79+
"--profile",
80+
"black",
81+
"--filter-files",
82+
--settings-path=pyproject.toml,
83+
]
84+
- repo: https://github.com/hadialqattan/pycln
85+
rev: v2.4.0
86+
hooks:
87+
- id: pycln
88+
args: [--config=pyproject.toml]
89+
- repo: https://github.com/pycqa/docformatter
90+
rev: v1.7.5
91+
hooks:
92+
- id: docformatter
93+
# - repo: https://github.com/MarcoGorelli/absolufy-imports
94+
# rev: v0.3.1
95+
# hooks:
96+
# - id: absolufy-imports
97+
- repo: https://github.com/asottile/pyupgrade
98+
rev: v3.15.0
99+
hooks:
100+
- id: pyupgrade
101+
entry: pyupgrade --py39-plus --keep-runtime-typing
102+
types:
103+
- python
104+
- repo: https://github.com/gitleaks/gitleaks
105+
rev: v8.18.2
106+
hooks:
107+
- id: gitleaks
108+
- repo: https://github.com/asottile/yesqa
109+
rev: v1.5.0
110+
hooks:
111+
- id: yesqa
112+
# TODO: Uncomment after typing the SDK
113+
# - repo: https://github.com/pre-commit/mirrors-mypy
114+
# rev: v1.8.0
115+
# hooks:
116+
# - id: mypy
117+
# language: system
118+
# entry: mypy .
119+
# pass_filenames: false
120+
# # IMPORTANT!
121+
# # Keep args same as tool.mypy section in pyproject.toml
122+
# args:
123+
# [
124+
# --allow-subclassing-any,
125+
# --allow-untyped-decorators,
126+
# --check-untyped-defs,
127+
# --exclude, ".*migrations/.*.py",
128+
# --exclude, "backend/prompt/.*",
129+
# --exclude, "document_display_service/.*",
130+
# --exclude, "pkgs/unstract-connectors/tests/.*",
131+
# --exclude, "pkgs/unstract-core/.*",
132+
# --exclude, "pkgs/unstract-flags/src/unstract/flags/.*",
133+
# --exclude, "sdks/.*",
134+
# --exclude, "unstract-document-service/.*",
135+
# --exclude, "__pypackages__/.*",
136+
# --follow-imports, "silent",
137+
# --ignore-missing-imports,
138+
# --implicit-reexport,
139+
# --pretty,
140+
# --python-version=3.9,
141+
# --show-column-numbers,
142+
# --show-error-codes,
143+
# --strict,
144+
# --warn-redundant-casts,
145+
# --warn-return-any,
146+
# --warn-unreachable,
147+
# --warn-unused-configs,
148+
# --warn-unused-ignores,
149+
# ]
150+
- repo: https://github.com/igorshubovych/markdownlint-cli
151+
rev: v0.39.0
152+
hooks:
153+
- id: markdownlint
154+
args: [--disable, MD013]
155+
- id: markdownlint-fix
156+
args: [--disable, MD013]
157+
- repo: https://github.com/pdm-project/pdm
158+
rev: 2.12.3
159+
hooks:
160+
- id: pdm-lock-check

README.md

+61
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
11
# unstract-python-client
22
Python client for the Unstract LLM-powered structured data extraction platform
3+
4+
5+
## Installation
6+
7+
You can install the Unstract Python Client using pip:
8+
9+
```bash
10+
pip install unstract-client
11+
```
12+
13+
## Usage
14+
15+
First, import the `APIDeploymentsClient` from the `client` module:
16+
17+
```python
18+
from unstract.api_deployments.client import APIDeploymentsClient
19+
```
20+
21+
Then, create an instance of the `APIDeploymentsClient`:
22+
23+
```python
24+
client = APIDeploymentsClient(api_url="url", api_key="your_api_key")
25+
```
26+
27+
Now, you can use the client to interact with the Unstract API deployments API:
28+
29+
```python
30+
try:
31+
adc = APIDeploymentsClient(
32+
api_url=os.getenv("UNSTRACT_API_URL"),
33+
api_key=os.getenv("UNSTRACT_API_DEPLOYMENT_KEY"),
34+
api_timeout=10,
35+
logging_level="DEBUG",
36+
)
37+
# Replace files with pdfs
38+
response = adc.structure_file(
39+
["<files>"]
40+
)
41+
print(response)
42+
if response["pending"]:
43+
while True:
44+
p_response = adc.check_execution_status(
45+
response["status_check_api_endpoint"]
46+
)
47+
print(p_response)
48+
if not p_response["pending"]:
49+
break
50+
print("Sleeping and checking again in 5 seconds..")
51+
time.sleep(5)
52+
except APIDeploymentsClientException as e:
53+
print(e)
54+
```
55+
56+
57+
## Questions and Feedback
58+
59+
On Slack, [join great conversations](https://join-slack.unstract.com/) around LLMs, their ecosystem and leveraging them to automate the previously unautomatable!
60+
61+
[Unstract Cloud](https://unstract.com/): Signup and Try!
62+
63+
[Unstract developer documentation](https://docs.unstract.com/): Learn more about Unstract and its API.

0 commit comments

Comments
 (0)