Skip to main content

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.2.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

contract_analysis-0.1.2-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file contract_analysis-0.1.2.tar.gz.

File metadata

  • Download URL: contract_analysis-0.1.2.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

Hashes for contract_analysis-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a3c15860a25e5622c29211565dd2673c4424a5819cf7c99632767975ab6814ec
MD5 6281e5ccad13c3044acac5f999f64513
BLAKE2b-256 c75ebaf5109226414dd3dc9480e02d9a0e9107a05ab44df74d24466f89b7b0c5

See more details on using hashes here.

File details

Details for the file contract_analysis-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for contract_analysis-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0263c275834598ad07d2bf7b53d9db23cdb5ab5f8408671a8d9aba18a5cdb3fb
MD5 3dd4d018cf862774f65bcca473d0bd53
BLAKE2b-256 ee0c3ae81d2e950f270b5a2aaa0f27e6da736a56a6986747e9f262141d390890

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page