WeedFS¶
Main PyWeed module. Contains WeedFS class
- class pyweed.weed.WeedFS(master_addr='localhost', master_port=9333)[source]¶
- __init__(master_addr='localhost', master_port=9333)[source]¶
Creates WeedFS instance.
- Args:
master_addr: Address of weed-fs master server (default: localhost)
master_port: Weed-fs master server port (default: 9333)
- Returns:
- WeedFS instance.
- file_exists(fid)[source]¶
Checks if file with provided fid exists
- Args:
- fid: File identifier <volume_id>,<file_name_hash>
- Returns:
- True if file exists. False if not.
- get_file(fid)[source]¶
Get file from WeedFS.
Returns file content. May be problematic for large files as content is stored in memory.
- Args:
- fid: File identifier <volume_id>,<file_name_hash>
- Returns:
- Content of the file with provided fid or None if file doesn’t exist on the server
New in version 0.3.1.
- get_file_location(volume_id)[source]¶
Get location for the file, WeedFS volume is choosed randomly
Parameters: volume_id (integer) – volume_id Return type: namedtuple FileLocation {“public_url”:””, “url”:”“}
- get_file_size(fid)[source]¶
Gets size of uploaded file Or None if file doesn’t exist.
- Args:
- fid: File identifier <volume_id>,<file_name_hash>
- Returns:
- Int or None
- get_file_url(fid)[source]¶
Get url for the file
Parameters: fid (string) – File ID Return type: string
- upload_file(path=None, stream=None, name=None, **kwargs)[source]¶
Uploads file to WeedFS
I takes either path or stream and name and upload it to WeedFS server.
Returns fid of the uploaded file.
Parameters: - path (string) –
- stream (string) –
- name (string) –
Return type: string or None
Utils¶
This is helper module that contains functions to easeup communication with weed-fs
- pyweed.utils.delete_data(url, *args, **kwargs)[source]¶
Deletes data under provided url
Returns status as boolean.
- Args:
url: address of file to be deleted
New in version 0.3.2: additional_headers: (optional) Additional headers to be used with request
- Returns:
- Boolean. True if request was successful. False if not.
- pyweed.utils.get_data(url, *args, **kwargs)[source]¶
Gets data from url as text
Returns content under the provided url as text
- Args:
url: address of the wanted data
New in version 0.3.2: additional_headers: (optional) Additional headers to be used with request
- Returns:
- string
- pyweed.utils.get_raw_data(url, *args, **kwargs)[source]¶
Gets data from url as bytes
Returns content under the provided url as bytes ie. for binary data
- Args:
url: address of the wanted data
New in version 0.3.2: additional_headers: (optional) Additional headers to be used with request
- Returns:
- bytes
- pyweed.utils.post_file(url, filename, file_stream, *args, **kwargs)[source]¶
Uploads file to provided url.
Returns contents as text
- Args:
url: address where to upload file
filename: Name of the uploaded file
file_stream: file like object to upload
New in version 0.3.2: additional_headers: (optional) Additional headers to be used with request
- Returns:
- string