Skip to main content

An API wrapper for Gofile API

Project description

Gofile2

from gofile2 import Gofile

async with Gofile() as g:
    await g.upload("/home/itz-fork/photo.png")

An API Wrapper for Gofile API.

About API

Gofile is in BETA version and this API will evolve over time. Check regularly if changes have been made.

Current version is compatible with 2025-05-16

Installation

Install via pypi Downloads

pip3 install gofile2

To install development version Gofile2, run the following command

pip install git+https://github.com/Itz-fork/Gofile2.git

Usage

1. Import Gofile2 in your python file

Asynchronous version

from gofile2 import Gofile

Synchronous version

from gofile2 import Sync_Gofile

2. Create an instance of Gofile2

Asynchronous version

g_a = Gofile(token="your_gofile_api_token_here")

Synchronous version

g_a = Sync_Gofile(token="your_gofile_api_token_here")

All API requests require authentication via a bearer token, which is sent automatically in the Authorization header. Tokens can be generated from the profile page. Guest uploads (without a token) are supported for the upload method only.

The token can be set at initialization or passed per-method call. When both are provided, the per-method token takes priority. You can also initialize without a token and pass it to individual method calls:

# Initialize without a token
g_a = Gofile()

# Pass token per method call
await g_a.create_folder("parent_id", token="your_token")
await g_a.get_content("folder_id", token="another_token")

3. Everything Done! Now Play with it!

Asynchronous version with context manager (recommended)

async with Gofile(token="your_token") as g:
    # Upload a file
    await g.upload(file="path_to_your_file")

    # Upload a file to a specific folder
    await g.upload(file="path_to_your_file", folderId="folder_id")

    # Upload a file to a specific region
    await g.upload(file="path_to_your_file", server="upload-eu-par")

    # Upload a folder
    await g.upload_folder(path="path_to_your_folder")

    # Create folder
    await g.create_folder(parentFolderId="your_root_folder_id", folderName="Folder Name")

    # Update content attributes (rename, set description, tags, etc.)
    await g.update_content(contentId="id_of_content", attribute="name", attributeValue="new_name.txt")

    # Delete file or folder
    await g.delete_content(contentId="id_of_the_file_or_folder")

    # Get content information
    await g.get_content(contentId="folder_id")

    # Search for content within a folder
    await g.search_content(contentId="folder_id", searchedString="my_file")

    # Copy content to another folder
    await g.copy_content(contentsId="content_id", folderId="destination_folder_id")

    # Move content to another folder
    await g.move_content(contentsId="content_id", folderId="destination_folder_id")

    # Import public content into your account
    await g.import_content(contentsId="content_id")

    # Create a direct link
    await g.create_direct_link(contentId="content_id", expireTime=1735689600)

    # Update a direct link
    await g.update_direct_link(contentId="content_id", directLinkId="link_id", expireTime=1735689600)

    # Delete a direct link
    await g.delete_direct_link(contentId="content_id", directLinkId="link_id")

    # Get account ID
    await g.get_account_id()

    # Get account information
    await g.get_account(accountId="account_id")

    # Reset API token (new token will be sent via email)
    await g.reset_token(accountId="account_id")

    # Any method also accepts a per-call token to override the instance token
    await g.get_content(contentId="folder_id", token="different_token")

Synchronous version with context manager

with Sync_Gofile(token="your_token") as g:
    g.upload(file="path_to_your_file")
    g.upload_folder(path="path_to_your_folder")
    g.create_folder(parentFolderId="root_folder_id", folderName="My Folder")
    g.update_content(contentId="content_id", attribute="name", attributeValue="new_name.txt")
    g.delete_content(contentId="content_id")
    g.get_content(contentId="folder_id")
    g.search_content(contentId="folder_id", searchedString="my_file")
    g.copy_content(contentsId="content_id", folderId="destination_folder_id")
    g.move_content(contentsId="content_id", folderId="destination_folder_id")
    g.import_content(contentsId="content_id")
    g.create_direct_link(contentId="content_id", expireTime=1735689600)
    g.update_direct_link(contentId="content_id", directLinkId="link_id", expireTime=1735689600)
    g.delete_direct_link(contentId="content_id", directLinkId="link_id")
    g.get_account_id()
    g.get_account(accountId="account_id")
    g.reset_token(accountId="account_id")

    # Any method also accepts a per-call token to override the instance token
    g.get_content(contentId="folder_id", token="different_token")

Manual session management

g_a = Gofile(token="your_token")

await g_a.upload(file="path_to_your_file")

# Close the session when done
await g_a.done()

Regional Upload Servers

By default, uploads go through upload.gofile.io which automatically selects the best server. You can also specify a regional server:

Server Location
upload-eu-par Paris
upload-na-phx Phoenix
upload-ap-sgp Singapore
upload-ap-hkg Hong Kong
upload-ap-tyo Tokyo
upload-sa-sao São Paulo
await g.upload(file="file.txt", server="upload-eu-par")

Multi-Account Usage

All methods accept an optional token parameter, allowing you to use multiple accounts with a single client instance. The per-method token overrides the instance token for that specific call:

Asynchronous version

async with Gofile() as g:
    # Operate on account A
    await g.create_folder("parent_id", folderName="Folder A", token="token_account_a")
    await g.upload(file="file.txt", folderId="folder_id", token="token_account_a")

    # Operate on account B without reinitializing
    await g.create_folder("parent_id", folderName="Folder B", token="token_account_b")
    await g.get_content(contentId="folder_id", token="token_account_b")

Synchronous version

with Sync_Gofile() as g:
    # Operate on account A
    g.create_folder("parent_id", folderName="Folder A", token="token_account_a")

    # Operate on account B without reinitializing
    g.get_content(contentId="folder_id", token="token_account_b")

Docs

  • Gofile(token: Optional[str] = None)

    • Create an async Gofile2 client
    • token: Optional[str] - API token for authentication
  • Sync_Gofile(token: Optional[str] = None)

    • Create a sync Gofile2 client
    • token: Optional[str] - API token for authentication
  • upload(file: str, folderId: Optional[str] = None, server: Optional[str] = None, token: Optional[str] = None) -> Dict[str, Any]

    • Upload a file to Gofile storage
    • file: str - Path to file to upload
    • folderId: Optional[str] - Destination folder ID
    • server: Optional[str] - Regional upload server
    • token: Optional[str] - Per-request token (overrides instance token)
  • upload_folder(path: str, folderId: Optional[str] = None, delay: int = 3, server: Optional[str] = None, token: Optional[str] = None) -> List[Dict[str, Any]]

    • Upload all files in a folder
    • path: str - Path to the folder to upload
    • folderId: Optional[str] - Destination folder ID
    • delay: int - Time interval between uploads in seconds
    • server: Optional[str] - Regional upload server
    • token: Optional[str] - Per-request token (overrides instance token)
  • create_folder(parentFolderId: str, folderName: Optional[str] = None, public: Optional[bool] = None, token: Optional[str] = None) -> Dict[str, Any]

    • Create a new folder
    • parentFolderId: str - Parent folder ID
    • folderName: Optional[str] - Custom folder name
    • public: Optional[bool] - Whether folder is publicly accessible
    • token: Optional[str] - Per-request token (overrides instance token)
  • update_content(contentId: str, attribute: str, attributeValue: Any, token: Optional[str] = None) -> Dict[str, Any]

    • Update an attribute of a file or folder
    • contentId: str - Content ID
    • attribute: str - Attribute to update (name, description, tags, public, expiry, password)
    • attributeValue: Any - New value for the attribute
    • token: Optional[str] - Per-request token (overrides instance token)
  • delete_content(contentId: str, token: Optional[str] = None) -> Dict[str, Any]

    • Delete a file or folder
    • contentId: str - Comma-separated list of content IDs to delete
    • token: Optional[str] - Per-request token (overrides instance token)
  • get_content(contentId: str, password: Optional[str] = None, token: Optional[str] = None) -> Dict[str, Any]

    • Get information about a folder and its contents
    • contentId: str - Content ID (must be a folder ID)
    • password: Optional[str] - SHA-256 hash of the password for password-protected content
    • token: Optional[str] - Per-request token (overrides instance token)
  • search_content(contentId: str, searchedString: str, token: Optional[str] = None) -> Dict[str, Any]

    • Search for files and folders within a specific parent folder
    • contentId: str - Folder ID to search within
    • searchedString: str - Search string to match against content names or tags
    • token: Optional[str] - Per-request token (overrides instance token)
  • copy_content(contentsId: str, folderId: str, password: Optional[str] = None, token: Optional[str] = None) -> Dict[str, Any]

    • Copy files or folders to a destination folder
    • contentsId: str - Comma-separated list of content IDs to copy
    • folderId: str - Destination folder ID
    • password: Optional[str] - SHA-256 hash of the password for password-protected content
    • token: Optional[str] - Per-request token (overrides instance token)
  • move_content(contentsId: str, folderId: str, token: Optional[str] = None) -> Dict[str, Any]

    • Move files or folders to a destination folder
    • contentsId: str - Comma-separated list of content IDs to move
    • folderId: str - Destination folder ID
    • token: Optional[str] - Per-request token (overrides instance token)
  • import_content(contentsId: str, password: Optional[str] = None, token: Optional[str] = None) -> Dict[str, Any]

    • Import public content into your account's root folder
    • contentsId: str - Comma-separated list of content IDs to import
    • password: Optional[str] - SHA-256 hash of the password for password-protected content
    • token: Optional[str] - Per-request token (overrides instance token)
  • create_direct_link(contentId: str, expireTime: Optional[int] = None, sourceIpsAllowed: Optional[List[str]] = None, domainsAllowed: Optional[List[str]] = None, domainsBlocked: Optional[List[str]] = None, auth: Optional[List[str]] = None, token: Optional[str] = None) -> Dict[str, Any]

    • Create a direct access link to content
    • contentId: str - Content ID
    • expireTime: Optional[int] - Unix timestamp when the link should expire
    • sourceIpsAllowed: Optional[List[str]] - List of IP addresses allowed to access the link
    • domainsAllowed: Optional[List[str]] - List of domains allowed to access the link
    • domainsBlocked: Optional[List[str]] - List of domains blocked from accessing the link
    • auth: Optional[List[str]] - List of "user:password" combinations for basic authentication
    • token: Optional[str] - Per-request token (overrides instance token)
  • update_direct_link(contentId: str, directLinkId: str, expireTime: Optional[int] = None, sourceIpsAllowed: Optional[List[str]] = None, domainsAllowed: Optional[List[str]] = None, domainsBlocked: Optional[List[str]] = None, auth: Optional[List[str]] = None, token: Optional[str] = None) -> Dict[str, Any]

    • Update a direct link's configuration
    • contentId: str - Content ID
    • directLinkId: str - Direct link ID to update
    • expireTime: Optional[int] - New Unix timestamp for link expiration
    • sourceIpsAllowed: Optional[List[str]] - Updated list of allowed IP addresses
    • domainsAllowed: Optional[List[str]] - Updated list of allowed domains
    • domainsBlocked: Optional[List[str]] - Updated list of blocked domains
    • auth: Optional[List[str]] - Updated list of "user:password" combinations
    • token: Optional[str] - Per-request token (overrides instance token)
  • delete_direct_link(contentId: str, directLinkId: str, token: Optional[str] = None) -> Dict[str, Any]

    • Delete a direct link
    • contentId: str - Content ID
    • directLinkId: str - Direct link ID to delete
    • token: Optional[str] - Per-request token (overrides instance token)
  • get_account_id(token: Optional[str] = None) -> Dict[str, Any]

    • Get the account ID associated with the current API token
    • token: Optional[str] - Per-request token (overrides instance token)
  • get_account(accountId: str, token: Optional[str] = None) -> Dict[str, Any]

    • Get detailed information about a specific account
    • accountId: str - Account ID to retrieve information for
    • token: Optional[str] - Per-request token (overrides instance token)
  • reset_token(accountId: str, token: Optional[str] = None) -> Dict[str, Any]

    • Reset the API token for an account. A new token will be sent via email
    • accountId: str - Account ID
    • token: Optional[str] - Per-request token (overrides instance token)
  • done() -> None

    • Close the HTTP session

Contact

You can find me on; Telegram, Bluesky, Discord

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

gofile2-2.1.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

gofile2-2.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file gofile2-2.1.tar.gz.

File metadata

  • Download URL: gofile2-2.1.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for gofile2-2.1.tar.gz
Algorithm Hash digest
SHA256 96fd3ff819a543882b611b600d78a44baee288f55d1e94b6438cbb9b0ffb4011
MD5 eba4777314816c1991e86b14175c0691
BLAKE2b-256 3e4126eaf53d585a291d7a86a12a1d796f7f54e2f45f7240b92d3dff54d330e2

See more details on using hashes here.

File details

Details for the file gofile2-2.1-py3-none-any.whl.

File metadata

  • Download URL: gofile2-2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for gofile2-2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e5cc1faf334d04050fa239b1bc787541462260134454113b6d5c8dd2bd81ecd1
MD5 37389bf03437582473352e8e17099a78
BLAKE2b-256 b3e086d0825d66e648627f8e161d99a5f49c115eb65d1dcd90079f7d9dc18fe0

See more details on using hashes here.

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