Skip to content

Refactoring and PDM Integration #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish Python Package

on:
release:
types:
- published

jobs:
pypi-publish:
name: upload release to PyPI
runs-on: ubuntu-20.04
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}

- name: Setup PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: 3.11
version: 2.10.0

- name: Publish package distributions to PyPI
run: pdm publish
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
tests/data/*
160 changes: 160 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# - Added pkgs feature flag auto generated code to flake8 exclude list
# Force all unspecified python hooks to run python 3.10
default_language_version:
python: python3.9
default_stages:
- commit
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
# TODO: Exclude tests/test_data directory
exclude: ^tests/test_data/
exclude_types:
- "markdown"
- id: end-of-file-fixer
- id: check-yaml
args: [--unsafe]
- id: check-added-large-files
args: ["--maxkb=10240"]
- id: check-case-conflict
- id: check-docstring-first
- id: check-ast
- id: check-json
exclude: ".vscode/launch.json"
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-toml
- id: debug-statements
- id: detect-private-key
- id: check-merge-conflict
- id: check-symlinks
- id: destroyed-symlinks
- id: forbid-new-submodules
- id: mixed-line-ending
- id: no-commit-to-branch
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
args: ["-d", "relaxed"]
language: system
- repo: https://github.com/rhysd/actionlint
rev: v1.6.26
hooks:
- id: actionlint-docker
args: [-ignore, 'label ".+" is unknown']
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
args: [--config=pyproject.toml, -l 120]
language: system
exclude: |
(?x)^(
pkgs/unstract-flags/src/unstract/flags/evaluation_.*\.py|
)$
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
args: [--max-line-length=120]
exclude: |
(?x)^(
.*migrations/.*\.py|
unstract-core/tests/.*|
pkgs/unstract-flags/src/unstract/flags/evaluation_.*\.py|
)$
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
files: "\\.(py)$"
args:
[
"--profile",
"black",
"--filter-files",
--settings-path=pyproject.toml,
]
- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
hooks:
- id: pycln
args: [--config=pyproject.toml]
- repo: https://github.com/pycqa/docformatter
rev: v1.7.5
hooks:
- id: docformatter
# - repo: https://github.com/MarcoGorelli/absolufy-imports
# rev: v0.3.1
# hooks:
# - id: absolufy-imports
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
entry: pyupgrade --py39-plus --keep-runtime-typing
types:
- python
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.2
hooks:
- id: gitleaks
- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa
# TODO: Uncomment after typing the SDK
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.8.0
# hooks:
# - id: mypy
# language: system
# entry: mypy .
# pass_filenames: false
# # IMPORTANT!
# # Keep args same as tool.mypy section in pyproject.toml
# args:
# [
# --allow-subclassing-any,
# --allow-untyped-decorators,
# --check-untyped-defs,
# --exclude, ".*migrations/.*.py",
# --exclude, "backend/prompt/.*",
# --exclude, "document_display_service/.*",
# --exclude, "pkgs/unstract-connectors/tests/.*",
# --exclude, "pkgs/unstract-core/.*",
# --exclude, "pkgs/unstract-flags/src/unstract/flags/.*",
# --exclude, "sdks/.*",
# --exclude, "unstract-document-service/.*",
# --exclude, "__pypackages__/.*",
# --follow-imports, "silent",
# --ignore-missing-imports,
# --implicit-reexport,
# --pretty,
# --python-version=3.9,
# --show-column-numbers,
# --show-error-codes,
# --strict,
# --warn-redundant-casts,
# --warn-return-any,
# --warn-unreachable,
# --warn-unused-configs,
# --warn-unused-ignores,
# ]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.39.0
hooks:
- id: markdownlint
args: [--disable, MD013]
- id: markdownlint-fix
args: [--disable, MD013]
- repo: https://github.com/pdm-project/pdm
rev: 2.12.3
hooks:
- id: pdm-lock-check
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,63 @@
# unstract-python-client
Python client for the Unstract LLM-powered structured data extraction platform


## Installation

You can install the Unstract Python Client using pip:

```bash
pip install unstract-client
```

## Usage

First, import the `APIDeploymentsClient` from the `client` module:

```python
from unstract.api_deployments.client import APIDeploymentsClient
```

Then, create an instance of the `APIDeploymentsClient`:

```python
client = APIDeploymentsClient(api_url="url", api_key="your_api_key")
```

Now, you can use the client to interact with the Unstract API deployments API:

```python
try:
adc = APIDeploymentsClient(
api_url=os.getenv("UNSTRACT_API_URL"),
api_key=os.getenv("UNSTRACT_API_DEPLOYMENT_KEY"),
api_timeout=10,
logging_level="DEBUG",
)
# Replace files with pdfs
response = adc.structure_file(
["<files>"]
)
print(response)
if response["pending"]:
while True:
p_response = adc.check_execution_status(
response["status_check_api_endpoint"]
)
print(p_response)
if not p_response["pending"]:
break
print("Sleeping and checking again in 5 seconds..")
time.sleep(5)
except APIDeploymentsClientException as e:
print(e)
```


## Questions and Feedback

On Slack, [join great conversations](https://join-slack.unstract.com/) around LLMs, their ecosystem and leveraging them to automate the previously unautomatable!

[Unstract Cloud](https://unstract.com/): Signup and Try!

[Unstract developer documentation](https://docs.unstract.com/): Learn more about Unstract and its API.
Loading