A Python library for analyzing legal contracts using Azure services.
Project description
Contract Analysis Library
A Python library for analyzing legal contracts using Azure services:
- Azure Document Intelligence
- Azure Translator
- Azure OpenAI
- Azure Content Understanding
Features
- Document Translation: Automatically detect and translate contracts to a target language.
- Field Extraction: Extract structured fields using Azure Document Intelligence from a pre-trained model.
- Layout Analysis: Analyze document layout and extract text per page.
- Content Understanding: Use Azure Content Understanding for semantic analysis (using pre-trained model).
- GPT Integration: Leverage Azure OpenAI GPT for advanced prompt-based analysis.
Installation
pip install contract-analysis
Usage
from contract_analysis import ContractAnalysis
analyzer = ContractAnalysis(
document_path="<full-document-path>",
target_language="<target-language>", # e.g., 'en', 'fr'
translator_endpoint="<your-translator-endpoint>",
translator_region="<your-region>", # e.g., 'eastus'
# Optional: Content Understanding
cu_endpoint="<your-cu-endpoint>",
cu_api_version="<your-cu-api-version>",
cu_subscription_key="<your-subscription-key>",
cu_token_provider="<your-token-provider>",
cu_analyzer_id="<your-analyzer-id>",
# Optional: Document Intelligence
di_endpoint="<your-di-endpoint>",
di_model_id="<your-model-id>",
di_fields_list=["PartyA", "PartyB", "EffectiveDate"],
# Optional: GPT Integration
gpt_api_version="<gpt-api-version>",
gpt_endpoint="<gpt-endpoint>",
gpt_model="<gpt-deployment-name>",
prompt_registry={
"PromptName1": lambda: """
[FULL PROMPT TEXT HERE]
""",
"PromptName2": lambda: """
[FULL PROMPT TEXT HERE]
"""
}
)
Running Tests
To run the test suite:
$env:PYTHONPATH="src"; python -m unittest discover -s tests -p "test_*.py"
Project Structure
contract-analysis/
├── src/
│ └── contract_analysis/
│ ├── __init__.py
│ ├── document.py
│ ├── translation.py
│ ├── document_intelligence.py
│ ├── openai_gpt.py
│ ├── content_understanding.py
│ └── contract_analysis.py
├── tests/
│ ├── test_document.py
│ ├── test_translation.py
│ ├── test_document_intelligence.py
│ ├── test_openaigpt.py
│ ├── test_content_understanding.py
│ └── test_contract_analysis.py
├── examples/
│ ├── analyse_contract_example.py
│ └── compare_contracts_example.py
├── configuration/
│ └── config.yaml # excluded from version control
├── contracts/
│ └── sample files # excluded from version control
├── README.md
├── pyproject.toml
├── LICENSE
└── .gitignore
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
contract_analysis-0.1.1.tar.gz
(11.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contract_analysis-0.1.1.tar.gz.
File metadata
- Download URL: contract_analysis-0.1.1.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0b2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2167959d5a554a7eefc8459c620eac86a57eb35cac48f6400faa0d09eeb6289
|
|
| MD5 |
d51e3e92b88028b264df2993385f1fc6
|
|
| BLAKE2b-256 |
1aa8f05c076705f6a9cb5bbac2b9a0d77f32070d6db9dca9500e585a4d65b3d9
|
File details
Details for the file contract_analysis-0.1.1-py3-none-any.whl.
File metadata
- Download URL: contract_analysis-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0b2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ba1e07416581071f8b3f80389a6f0088e8e9cce566e686e9071541596863a43
|
|
| MD5 |
37285170ebc37e09282a627817851d18
|
|
| BLAKE2b-256 |
57549f797458b75c413412c5dc842e4ae83dbd5f458e5a647e751a5e1439bb31
|