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.0.tar.gz (17.9 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.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: contract_analysis-0.1.0.tar.gz
  • Upload date:
  • Size: 17.9 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.0.tar.gz
Algorithm Hash digest
SHA256 abe294461e816fe286ed0e088e57b46c6bc152b27c7271f3fcf130c0564b252a
MD5 9df63e9309b37c5c5e6b418204d3ffe0
BLAKE2b-256 b5fa5e8e2ea90272332ee260d8983f9e96869d88f4810f8c90e03665a040fe1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for contract_analysis-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b6602ff3c594efb29088c8a5eeac351ca60d8eb9b33a61b30962540fdf9c231
MD5 577683994bf28b347749c5e71a405aa3
BLAKE2b-256 d7310fd56eb09eb2b87f928fe226c0214d90385b932a9ca1187e823a5d771b2b

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