AnonFile
anonfile.AnonFile(object)
Implements the unofficial Python API for https://anonfiles.com .
Constructor
AnonFile.
__init__(self, token: str="undefined", timeout: Tuple[float, float]=AnonFile._timeout, total:
int=AnonFile._total, status_forcelist: List[int]=AnonFile._status_forcelist, backoff_factor:
int=AnonFile._backoff_factor, user_agent: str=AnonFile._user_agent, proxies: dict=AnonFile._proxies) ->
AnonFile
Create a new AnonFile
object. Provides many additional
parameter to configure the behavior of the underlying session object.
from anonfile import AnonFile
from faker import Faker
# faker needs to be installed separately
chrome_ua = Faker().chrome(version_from=90, version_to=93, build_from=4400, build_to=4500)
anon = AnonFile("my-secret-token", user_agent=chrome_ua)
In the example above we used the
faker
library to create a fake user agent, though this is not required. Same
goes for the token: you still use this library without specifying a token.
Fields
AnonFile.API -> str
Defines the base API address used to make requests to https://anonfiles.com and is primarily used by the library to build the endpoints.
Properties
self.retry_strategy -> Retry
The retry strategy returns the retry configuration made up of the number of total retries, the status force list as well as the backoff factor. It is used in the session property where these values are passed to the HTTP Adapter.
self.session -> Session
Create a custom session object. A request session provides cookie persistence, connection-pooling, and further configuration options.
Methods
AnonFile.upload(self, path: Union[str, Path], progressbar: bool=False, enable_logging:
bool=False) ->
ParseResponse
Upload a file located in path
to
https://anonfiles.com
Set enable_logging
to True
to store the
URL in a global config file.
from anonfile import AnonFile
anon = AnonFile()
upload = anon.upload('test.txt')
# https://anonfiles.com/9ee1jcu6u9/test_txt
print(upload.url.geturl())
Although anonfile
offers unlimited bandwidth, uploads
cannot exceed a file size of 20GB in theory. Due to technical difficulties
in the implementation, the upper cap occurs much earlier at around
500MB.
AnonFile.preview(self, url: str, path: Union[str, Path]=Path.cwd()) -> ParseResponse
Obtain meta data associated with this url
without committing
to a time-consuming download.
from anonfile import AnonFile
anon = AnonFile()
preview = anon.preview('https://anonfiles.com/b7NaVd0cu3/topsecret_mkv')
# File Size: 116271961B
print(f"File Size: {preview.size}B")
AnonFile.download(self, path: Union[str, Path]=Path.cwd(), progressbar: bool=False,
enable_logging:
bool=False) -> ParseResponse
Download a file from
https://anonfiles.com
given a url
. Set the download directory in path
(defaults to the current working directory). Set enable_logging
to True
to store the URL in a global config file.
from anonfile import AnonFile
from pathlib import Path
anon = AnonFile()
anon = AnonFile('my_token')
target_dir = Path.home().joinpath('Downloads')
result = anon.download("https://anonfiles.com/9ee1jcu6u9/test_txt", target_dir)
# WindowsPath('C:/Users/username/Downloads/test.txt')
print(result.file_path)