Skip to main content

A Python library for analyzing legal contracts using Azure services.

Project description

Contract Analysis Library

GitHub Repository

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.3.tar.gz (12.0 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.3-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: contract_analysis-0.1.3.tar.gz
  • Upload date:
  • Size: 12.0 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.3.tar.gz
Algorithm Hash digest
SHA256 c1c09997c2148a58f84da543b9bb4347b96f6efc45e8b9614ccf0b5b66102215
MD5 678866d2c2f73c9c644d4f6c406d79a1
BLAKE2b-256 4db613757276a22a1d2c452ffcce99865d70683d1b8062c0098731ab41c44f37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for contract_analysis-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5aab61e6ac2c52c4e890c9c185c853db1f32cc48fe3c59884b3499ab0272c5a9
MD5 c44ce93ac1564fea7f57eb24c03104c9
BLAKE2b-256 3e87285888f0b6442c874721d2636584652668624ed18210d386310b4b0b30eb

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