Skip to main content

A Python SDK for WeTransfer's Public API

Project description

WeTransfer Python SDK

A Python SDK for the WeTransfer's Public API

Installation

Use PYPI to install latest stable version:

pip install wetransfer

Checkout the repository and inside the repo's root directory use pip to install latest version to your environment with:

pip install .

Usage

Before starting make sure you have an API key acquired from Developers Portal.

As a first step you need to create a client:

from wetransfer.client import WTApiClient

kwargs = {"key": "<my-very-personal-api-key>"}
wt_client = WTApiClient(**kwargs)

After you have the client instance you need to authorize using this client:

wt_client.authorize()

If authorization is successful you should be able to create an new empty transfer

transfer = wt_client.create_transfer()

Afterwards you should be able to add items to it

from wetransfer.items import File

f1 = File("~/test.txt")
f2 = File("~/test2.txt")
transfer.add_items([f1, f2])

print(transfer)

After calling add_items method the upload process should start. As soon as it returns you should be able to see details for this transfer and access the url that your transfer is available for download.

The full code snippet is as follows:

import sys
from wetransfer.items import File, Link
from wetransfer.client import WTApiClient

kwargs = {"key": "<my-very-personal-api-key>"}
wt_client = WTApiClient(**kwargs)

if not wt_client.authorize():
    sys.exit(0)

transfer = wt_client.create_transfer()

f1 = File("./test.txt")
l1 = Link("https://wetransfer.com/", "WeTransfer Website")

transfer.add_items([f1, l1])

print(transfer)

which if you run it you should see something like:

Transfer with id: <id>, can be found in short url: <str>, with following items: ['Transfer item, file type, with size 10, name test.txt, and local path /Users/bla/test.txt, has 1 multi parts']

Helper methods

If you need to upload only file you can skip the File objects creation and use a helper function that allows you to specify a list of paths as strings and will add these for you a given Transfer

transfer.add_files(["file1.txt", "file2.txt"])

Similar method exist for URLs:

transfer.add_links(["https://wetransfer.com/", "http://www.visitgreece.gr/"])

Debugging

If you need to debug or investigate weird behaviours you can enable logs for this SDK by enabling the dedicated python logger

import logging

logging.basicConfig()
logging.getLogger("wetransfer-python-sdk").setLevel(logging.DEBUG)

kwargs = {"key": "<my-very-personal-api-key>"}
wt = WTApiClient(**kwargs)
...

You can set the severity level accordingly depending on the verbosity you desire.

Contributing

See dedicated section.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

wetransfer-0.0.1-py2.py3-none-any.whl (21.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wetransfer-0.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: wetransfer-0.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.14

File hashes

Hashes for wetransfer-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5b32230e0889ddae5fd80ffe50e2c0e4a90cdcd516308cd1f1072bc72a4a6fbf
MD5 759b8ea43e9ff88ab8355d1610b96450
BLAKE2b-256 90ee57a1d5e62aa18747d4fbd60f341ff73e82e472ca280b4664dec0f03ce374

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page