Skip to main content

Download files from the Cencora secure file transfer site

Project description

Purpose

This Python package can be used to download files from the Cencora (formerly Amerisource) secure file transfer site for ingest into clinical data systems.

Downloads are performed from the web-based secure site located at https://secure.amerisourcebergen.com/. FTP is not supported. (There are many easier ways to automate FTP-based downloads.)

Requirements

  • Python 3.10 or newer

Installation

Use pip to install the medberg package.

pip install medberg

Usage

Import the SecureSite class from the medberg module.

from medberg import SecureSite

Initialize a connection to the secure site by providing a username and password.

con = SecureSite(username='yourname', password='yourpassword')

A list of files is automatically downloaded at connection time and stored in the files variable. Files are represented by objects comprising a name, filesize, and upload date.

print(con.files)
# [File(name=340B037AM1234567890330.TXT, filesize=self.filesize='1.3MB', date='03/30/2025'),  ...]

print(con.files[0].name)
# 340B037AM1234567890330.TXT

print(con.files[0].filesize)
# 1.3MB

print(con.files[0].date)
# datetime.datetime(2025, 3, 30, 8, 13, 58)

Any individual file can be downloaded using the get method of the File class. Optional parameters can be specified for the save directory (save_dir) and local filename (save_name). If these are omitted, the file will be saved in the current working directory using the original filename by default.

con.files[0].get(save_dir='C:\\Users\\yourname\\Downloads\\',
                 save_name='new_filename.txt')

Files can also be downloaded using the get_file method of the SecureSite class. In this case, the file to download must be specified in the first parameter as either an instance of the File class or a string containing the filename as it appears on the remote site. The optional save_dir and save_name parameters are again available as with the File.get method.

# Using a File object
file_to_get = con.files[0]
con.get_file(file_to_get)

# Using a string filename
con.get_file('039A_012345678_0101.TXT')

When a file is downloaded using either of the methods above, the return value will be a pathlib Path object pointing to the local file.

Contributing

Pull requests are welcome. Please ensure all code submitted is formatted with Black and tested with pytest. For major changes, please open an issue first to discuss what you would like to change.

When editing the codebase locally, you may install medberg in development mode to use it in REPLs:

pip install -e '.[dev]'

License

This software is licensed under the MIT License.

Disclaimer

This package and its authors are not afiliated, associated, authorized, or endorsed by Cencora, Inc. All names and brands are properties of their respective owners.

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

medberg-1.0.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

medberg-1.0.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file medberg-1.0.0.tar.gz.

File metadata

  • Download URL: medberg-1.0.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for medberg-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e98599876c3f1c3bf051e99592f39cefcbc77a0e72e22fb744bb8d3e61db440a
MD5 4495eaaad51edeb01b4e8f4e189c2682
BLAKE2b-256 d8ce74e2844db8e62f398a11568f1627aefa9a8ec555917a61ba08ef78a478e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for medberg-1.0.0.tar.gz:

Publisher: python-publish.yml on eddie-cosma/medberg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file medberg-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: medberg-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for medberg-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1de6e98321d548251345c2ffd1fbf2171fbddccdbc4d0ca37ad57cdd9b2347f
MD5 452b5f1d5507cb1a7c35c9c9c80f264a
BLAKE2b-256 4cc438af0b4d7e783e1ae7e742115ff71f17739e3b729af4c20bc40b2c6f4680

See more details on using hashes here.

Provenance

The following attestation bundles were made for medberg-1.0.0-py3-none-any.whl:

Publisher: python-publish.yml on eddie-cosma/medberg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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