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
Metadata
Release files for medscope-api 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| medscope_api-0.1.0.tar.gz | 6.5 kB | Without provenance | Details for medscope_api-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| medscope_api-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for medscope_api-0.1.0-py3-none-any.whl |
Total release size: 12.8 kB
Release files / medscope_api-0.1.0.tar.gz
| Download URL | medscope_api-0.1.0.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f94c04e8460977991cc34a86c34f41293060413eff8a1021f2e36b831034e947
|
|
BLAKE2b-256 checksum How to use checksums |
2156b020da9628f6e9b53bd97cee60c2044e0e5a502f9df8c9cd42df62f275bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|
Release files / medscope_api-0.1.0-py3-none-any.whl
| Download URL | medscope_api-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3b952d0926caf221f907a7c5c04830e82665198688b0b3df636744faf561830
|
|
BLAKE2b-256 checksum How to use checksums |
61019a6a48f41b3d1c9d4bc3318804eace4c6e9b73948a281daee429b5b6e494
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|
Security for medscope-api 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.