Giter Site home page Giter Site logo

wetransfer-python-sdk's Introduction

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 and fill in your board name:

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(transfer_name="My very first 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(transfer_name="My very first 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.

wetransfer-python-sdk's People

Contributors

astrikos avatar infinitefor avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

infinitefor

wetransfer-python-sdk's Issues

Unable to create a new empty transfer

I have a valid API key, however when I try to create an empty transfer I get the following error

>>> T = wt_client.create_transfer()

DEBUG:wetransfer-python-sdk:POST request to <https://dev.wetransfer.com/v1/trans fers> with headers:<{'Content-Length': '23', 'Accept-Encoding': 'gzip, deflate', 'Accept': '/', 'User-Agent': 'WT python SDK v0.2.0', 'Connection': 'keep-aliv e', 'x-api-key': 'EqQpdRGyba5wIqniN29K771troLgjoHn89C4AjHr', 'Content-Type': 'ap plication/json'}> and body:<{"name": "WT Transfer"}>
DEBUG:wetransfer-python-sdk: POST <401> response from <https://dev.wetransfer.co m/v1/transfers> with headers:<{'x-amzn-RequestId': 'a1e1c65e-46d4-11e9-9c0d-01b5 f9dadaff', 'Content-Length': '40', 'Via': '1.1 efdf33ba79ee3aadbfdf7e2b6e838d71. cloudfront.net (CloudFront)', 'X-Cache': 'Error from cloudfront', 'X-Content-Typ e-Options': 'nosniff', 'x-amzn-Remapped-Connection': 'keep-alive', 'Strict-Trans port-Security': 'max-age=31536000; includeSubDomains;', 'x-amz-apigw-id': 'WkHgS E_DDoEFx4w=', 'x-amzn-Remapped-Content-Length': '40', 'Connection': 'keep-alive' , 'X-Amz-Cf-Id': 'Xpw1InyHef0Bsv1aqIv1lPy9I36tut7w_EXFtbXACyJ6M-yKDdqCYQ==', 'x- amzn-Remapped-Date': 'Fri, 15 Mar 2019 03:44:27 GMT', 'Date': 'Fri, 15 Mar 2019 03:44:27 GMT', 'Content-Type': 'application/json'}> and body:<{"error":"Missing Authorization header"}>
ERROR:wetransfer-python-sdk:Failed creating new transfer

Can't upload files, every upload ends in short link with 0 files

I'm using this code and trying to upload file, but this resulting in WeTrasfer link to empty board - "This board is empty" - no files.

kwargs = {"key":  "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}
wt_client = WTApiClient(**kwargs)

wt_client.authorize()

transfer = wt_client.create_transfer(transfer_name="New upload")
f1 = File("setup-lightshot.exe")
transfer.add_items([f1])

I'm getting this error messages only in debug mode:

ERROR:wetransfer-python-sdk:Failed closing upload for item id: XXXXXXXXXXXXXX
Transfer with id: XXXXXXXXXXXXXXXXXXXXXX, can be found in short url: https://we.tl/XXXXXXXXXXX, with following items: ['Transfer item, file type, with size 2784344, name setup-lightshot.exe, and local path C:\\Users\\XXXXXXXXXXXXXX\\Desktop\\setup-lightshot.exe, has 1 multi parts']
ERROR:wetransfer-python-sdk:Failed to upload item Transfer item, file type, with size 2784344, name setup-lightshot.exe, and local path C:\Users\XXXXXXXXXX\Desktop\setup-lightshot.exe, has 1 multi parts

In normal mode I got only this part:

Transfer with id: XXXXXXXXXXXXXXXXXXXXXX, can be found in short url: https://we.tl/XXXXXXXXXXX, with following items: ['Transfer item, file type, with size 2784344, name setup-lightshot.exe, and local path C:\\Users\\XXXXXXXXXXXXXX\\Desktop\\setup-lightshot.exe, has 1 multi parts']

But link has no files in it.

Bug in `add_files`

pypi version 0.2.0

In [146]: transfer.add_files(['deduped.pickle', 'merged.pickle'])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-168-182f4abb61a0> in <module>
----> 1 transfer.add_files(['deduped.pickle', 'merged.pickle'])

~/anaconda3/lib/python3.7/site-packages/wetransfer/transfer.py in add_files(self, file_paths)
    122                 self.transfer_items.append(File(path))
    123 
--> 124         return self.add_items()
    125 
    126     def add_links(self, urls):

TypeError: add_items() missing 1 required positional argument: 'items'

Bug in Transfer.add_links?

Hello,
Using wetransfer-0.0.1, in the implementation of Transfer.add_links it is written:

self.transfer_items.append(File(url))

I guess you would have wanted to write

self.transfer_items.append(Link(url))

instead?

Send b64 memonry encoded file

I have files stored in a database, well they are not actually on the db, but i have no direct access to the files so i have them in b64, is there any way to transfer them? should i store them in another path in the file system just to send them with add_items?

Modify Transfer/Board name

Hello,
Thank you for your library.
It would be nice to be able to name a transfer/a board differently from "Andreas' very first transfer from python!", which is hardcoded in the CreateTransfer class.
It appears in large print in the board when sharing the transfer.shortened_url:

screenshot from 2018-09-28 16-17-33

Can you modify it? Would you accept a PR?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.