Skip to main content

API Wrapper for ViKiNG FiLE API (https://vikingfile.com)

Project description

viking-file-python

API Wrapper for ViKiNG FiLE API

Features and Functionality

This Python library provides a convenient way to interact with the ViKiNG FiLE API, allowing you to:

  • Upload files (both local and remote URLs).
  • Delete files.
  • Rename files.
  • Check if a file exists.
  • List files in your account.
  • Manage files in specific paths/folders. .

Prerequisites

  • Python 3.13 or higher
  • A ViKiNG FiLE account (if you need to upload files to your account)

Installation Instructions

  1. Install the package using pip:

    pip install viking-file
    

Usage Guide

Initialization

Import the VikingClient or AsyncVikingClient class and initialize it with your user hash (if you want to upload files to your account, otherwise, leave it empty for anonymous upload):

from viking_file import VikingClient, AsyncVikingClient

# Synchronous client
client = VikingClient(user_hash="YOUR_USER_HASH")  # Replace with your actual user hash

# Asynchronous client
async_client = AsyncVikingClient(user_hash="YOUR_USER_HASH")  # Replace with your actual user hash

# also you can use context manager both synchronous and asynchronous

# with VikingClient(user_hash="YOUR_USER_HASH") as client:
    # Your code here

# async with AsyncVikingClient(user_hash="YOUR_USER_HASH") as async_client:
    # Your asynchronous code here

Uploading a Local File (Synchronous)

from viking_file import VikingClient
from pathlib import Path

client = VikingClient(user_hash="YOUR_USER_HASH")

# Upload a file
file_path = Path("path/to/your/file.txt")  # Replace with the actual path to your file
uploaded_file = client.upload_file(
    filepath=file_path,
    path="Optional/Path/On/Server"
)  # path argument is optional

print(f"Uploaded file hash: {uploaded_file.hash}")
print(f"Uploaded file name: {uploaded_file.name}")
print(f"Uploaded file URL: {uploaded_file.url}")

Uploading a Local File (Asynchronous)

import asyncio
from viking_file import AsyncVikingClient
from pathlib import Path


async def upload_file():
    client = AsyncVikingClient(user_hash="YOUR_USER_HASH")

    # Upload a file
    file_path = Path("path/to/your/file.txt")  # Replace with the actual path to your file
    uploaded_file = await client.upload_file(
        filepath=file_path,
        path="Optional/Path/On/Server"
    )  # path argument is optional

    print(f"Uploaded file hash: {uploaded_file.hash}")
    print(f"Uploaded file name: {uploaded_file.name}")
    print(f"Uploaded file URL: {uploaded_file.url}")


asyncio.run(upload_file())

Uploading a Remote File (Asynchronous)

import asyncio
from viking_file import AsyncVikingClient


async def upload_remote_file():
    client = AsyncVikingClient(user_hash="YOUR_USER_HASH")

    # Upload a remote file
    remote_url = "https://example.com/remote_file.zip"  # Replace with the actual URL
    uploaded_file = await client.upload_remote_file(
        url=remote_url,
        filename="new_name.zip",
        path="Optional/Path/On/Server"
    )  # filename and path arguments are optional

    print(f"Uploaded file hash: {uploaded_file.hash}")
    print(f"Uploaded file name: {uploaded_file.name}")
    print(f"Uploaded file URL: {uploaded_file.url}")


asyncio.run(upload_remote_file())

Deleting a File (Asynchronous)

import asyncio
from viking_file import AsyncVikingClient


async def delete_file():
    client = AsyncVikingClient(user_hash="YOUR_USER_HASH")

    # Delete a file
    file_hash = "FILE_HASH_TO_DELETE"  # Replace with the actual file hash
    await client.delete_file(file_hash)

    print(f"File {file_hash} deleted successfully.")


asyncio.run(delete_file())

Renaming a File (Asynchronous)

import asyncio
from viking_file import AsyncVikingClient


async def rename_file():
    client = AsyncVikingClient(user_hash="YOUR_USER_HASH")

    # Rename a file
    file_hash = "FILE_HASH_TO_RENAME"  # Replace with the actual file hash
    new_filename = "new_file_name.txt"
    await client.rename_file(file_hash, new_filename)

    print(f"File {file_hash} renamed to {new_filename} successfully.")


asyncio.run(rename_file())

Listing Files (Asynchronous)

import asyncio
from viking_file import AsyncVikingClient


async def list_files():
    client = AsyncVikingClient(user_hash="YOUR_USER_HASH")

    # List files on page 1
    page_number = 1
    files = await client.list_files(
        page=page_number,
        path="Optional/Path/On/Server"
    )  # path argument is optional

    for file in files:
        print(f"File Hash: {file.hash}, Name: {file.name}, Size: {file.size}, URL: {file.url}")


asyncio.run(list_files())

Listing all files (Asynchronous)

import asyncio
from viking_file import AsyncVikingClient


async def list_all_files():
    client = AsyncVikingClient(user_hash="YOUR_USER_HASH")

    # List all files
    files = await client.list_all_files(
        path="Optional/Path/On/Server"
    )  # path argument is optional

    for file in files:
        print(f"File Hash: {file.hash}, Name: {file.name}, Size: {file.size}, URL: {file.url}")


asyncio.run(list_all_files())

Getting File Information (Asynchronous)

import asyncio
from viking_file import AsyncVikingClient


async def get_file_information():
    client = AsyncVikingClient(user_hash="YOUR_USER_HASH")

    # Get file information
    file_hash = "FILE_HASH_TO_GET_INFO"  # Replace with the actual file hash
    file = await client.get_file(file_hash)


asyncio.run(get_file_information())

API

The viking_file/api.py file contains the low-level API functions that are used by the VikingClient and AsyncVikingClient classes. These functions are primarily intended for internal use but can be used directly if needed.

Contributing Guidelines

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Implement your changes.
  4. Write tests for your changes.
  5. Ensure all tests pass.
  6. Submit a pull request.

License Information

This project is licensed under the MIT License

Contact/Support Information

For questions, bug reports, or feature requests, please open an issue on the GitHub repository.

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

viking_file-1.0.7.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

viking_file-1.0.7-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file viking_file-1.0.7.tar.gz.

File metadata

  • Download URL: viking_file-1.0.7.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for viking_file-1.0.7.tar.gz
Algorithm Hash digest
SHA256 151b92dec70d9203536d45bfc9d4615142314198b39b2527f7243b15533d7c98
MD5 010c3d91f0dc232fb66b515fea69b6fd
BLAKE2b-256 e350495e7b9cd4ebc79967a5c1a2ffb92ca278243a4338aed0b5ce73173bf125

See more details on using hashes here.

File details

Details for the file viking_file-1.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for viking_file-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d5a480bccdfeccd5ba88583f841f1c4af51edc34b9113b6e59c9e91f1a5721a9
MD5 2203d45d2038501d879b01a500953d3d
BLAKE2b-256 09bc9a1638dab1a95571fe709c34fc85967dd6dd7a5764c9b586420ecc7c9b93

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