Skip to main content

Python client library for the MedScope API

Project description

MedScope API for Python

Official Python client for the MedScope API.

Use this package if you want to send documents easily to MedScope from Python without building HTTP requests, headers, file uploads, or error handling yourself.

Python 3.10 or newer is required.

The client sends requests to:

https://api.medscope.info

Install

From PyPI:

pip install medscope-api

From this repository:

pip install ./code

If you are already inside the code directory:

pip install .

Set Your API Key

You can pass the API key directly:

from medscope import MedScope

client = MedScope(api_key="your_medscope_api_key")

For applications that make multiple requests, use the client as a context manager so pooled network connections are closed deterministically:

from medscope import MedScope

with MedScope(api_key="your_medscope_api_key") as client:
    result = client.extract("your_doctors_letter.pdf")

Or set it once as an environment variable:

export MEDSCOPE_API_KEY="your_medscope_api_key"

Then create the client without passing the key:

from medscope import MedScope

client = MedScope()

Test The API Server Connection

from medscope import MedScope

client = MedScope()

print(client.health())

Extract Data From A PDF

from medscope import MedScope

client = MedScope(api_key="your_medscope_api_key")

result = client.extract(
    "your_doctors_letter.pdf",
)

print(result)

extract(...) accepts a file path (str or PathLike), PDF bytes, or an open binary file object.

Options

You can enable optional API features with flags:

from medscope import MedScope

client = MedScope(
    api_key="your_medscope_api_key",
    flags={
        "include_fhir": True,
        "include_raw_text": False,
    },
)

result = client.extract(
    "your_doctors_letter.pdf",
)

You can also pass flags for a single request:

result = client.extract(
    "your_doctors_letter.pdf",
    flags={"include_fhir": True},
)

Request-level flags override client-level flags.

Unknown flags are allowed and sent as query parameters. This lets the API support new flags without requiring an immediate client update.

Client Configuration

The default request timeout is 120 seconds. You can configure it globally or for a single request:

client = MedScope(api_key="your_medscope_api_key", timeout=180)
result = client.extract("your_doctors_letter.pdf", timeout=240)

For local development or staging, pass a different API URL:

client = MedScope(
    api_key="your_medscope_api_key",
    base_url="https://staging-api.example.com",
)

Exclude Data Blocks

Use exclude to remove specific entity blocks from the returned structured_data and quality sections:

result = client.extract(
    "your_doctors_letter.pdf",
    exclude=["medication", "allergies"],
)

You can also pass a comma-separated string:

result = client.extract(
    "your_doctors_letter.pdf",
    exclude="medication,allergies",
)

Available Methods

client.health()
client.extract("your_doctors_letter.pdf")

Errors

The client raises MedScopeAuthenticationError if no API key is configured for a protected request.

The client raises MedScopeAPIError if the API returns an error response or an unexpected response.

MedScopeAPIError.status_code contains the HTTP status when one was received, and MedScopeAPIError.response contains the parsed error response. These fields may contain sensitive medical information and should not be logged without appropriate redaction.

from medscope import MedScope, MedScopeAPIError, MedScopeAuthenticationError

client = MedScope(api_key="your_medscope_api_key")

try:
    result = client.extract("your_doctors_letter.pdf")
except MedScopeAuthenticationError:
    print("Missing API key")
except MedScopeAPIError as error:
    print(error)

Development

Use this only if you want to work on the client library itself:

pip install -e ".[dev]"
pytest

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

medscope_api-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

medscope_api-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: medscope_api-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for medscope_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f94c04e8460977991cc34a86c34f41293060413eff8a1021f2e36b831034e947
MD5 850649f6f309d543a8c496f2fafd4b92
BLAKE2b-256 2156b020da9628f6e9b53bd97cee60c2044e0e5a502f9df8c9cd42df62f275bf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: medscope_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for medscope_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3b952d0926caf221f907a7c5c04830e82665198688b0b3df636744faf561830
MD5 4bccb336357444a31803a8143d2c1204
BLAKE2b-256 61019a6a48f41b3d1c9d4bc3318804eace4c6e9b73948a281daee429b5b6e494

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