Client

M-Files client methods.

For more information, see: https://developer.m-files.com/APIs/REST-API/Reference

class MFilesClient(server='http://localhost/m-files/REST/', user=None, password=None, vault=None)

M-Files client.

Parameters:
  • server (str) – API URL. Defaults to "http://localhost/m-files/REST/"
  • user (str) – User to login with. If not supplied it will be fetched from environment variable MFILES_USER, if not set it will be fetched using input().
  • password (str) – User password. If not supplied it will be fetched from environment variable MFILES_PASS, if not set it will be fetched using getpass().
  • vault (str) – M-Files vault GUID to connect to.
check_in(object_id, object_version, object_type=0)

Check in an object to M-Files.

check_out(object_id, object_type=0)

Check out an object from M-Files.

class_details(class_id)

Get details for a specific class in the M-Files vault.

classes()

Get all classes in the M-Files vault.

create_object(name, object_type=0, object_class=0, extra_info=None, file_info=None)

Create M-Files object and upload it to the vault.

Parameters:
  • name (str) – Name of new object.
  • object_type (str, int) – Object type. If integer, the type will not be attempted to be translated. If string, the type will be transated into the property ID the server expects for the given type.
  • object_class (str, int) – Object class, same translation principle as for object_type.
  • extra_info (dict) – Additional object information.
  • file_info (dict) – Eventual file information for object. Dict that must contain keys UploadID, Title, Extension, Size.
Raises:

MFilesException – If the object can’t be created.

Returns:

Dictionary with object information.

Return type:

dict

delete_object(object_type, object_id)

Delete M-Files object.

Note

Deleting an object means flagging an object for deletion. Most users will not see the object anymore, but administators will still be able to access it.

destroy_object(object_type, object_id)

Destroy M-Files object.

Caution

Destroying an object means unrecoverably deleting all versions of the object. Use with caution.

download_file(local_path, object_type, object_id, file_id, object_version='latest')

Download a file from M-Files.

Parameters:
  • object_type (int) – Object type ID.
  • object_id (int) – Object ID.
  • file_id (int) – File ID.
  • object_version (int, str) – Object version. Defaults to "latest".
  • local_path (str) – Path to download file to.
Raises:

MFilesException – If the file can’t be downloaded.

Returns:

True if file is found and downloaded successfully.

Return type:

bool

download_file_name(file_name, local_path=None)

Download a file from M-Files by its name.

Caution

This searches for the file and downloads the top result. This is not always guaranteed to be the intended file. A better way is to use search to find the correct file and then use the function download_file() to download the file by using file and object id.

Parameters:
  • file_name (str) – Name of file to download.
  • local_path (str) – Path to download file to. Defaults to file name and current directory.
Returns:

True if file is found and downloaded.

Return type:

bool

get(endpoint)

General purpose GET method.

Parameters:endpoint (str) – Endpoint on form "path/to/endpoint".
Raises:MFilesException – If request returns status code != 200.
Returns:Dictionary with request result.
Return type:dict
get_info(name, category='object')

Get general info of a type by name.

Parameters:
  • name (str) – Name of type to get info from.
  • category (str) – Type name. Can be any of "object", "class", "property". Defaults to "object".
Raises:

MFilesException – If the property name can’t be found.

Returns:

Dictionary with information about the type.

Return type:

dict

get_info_id(type_id, category='object')

Get general info of a type by id.

Parameters:
  • type_id (str) – ID of type to get info from.
  • category (str) – Type category. Can be any of "object", "class", "property". Defaults to "object".
Raises:

MFilesException – If the property ID can’t be found.

Returns:

Dictionary with information about the type.

Return type:

dict

get_property(property_name, owners, property_value)

Get a certain property built as M-Files expects it.

Parameters:
  • property_name (str) – Property name.
  • owners (list) – List of ints with possible owners IDs.
  • property_value (any) – Value to set property to.
Returns:

Property with required keys and values.

Return type:

dict

get_types(category='object')

Get info for all types from a type category.

Parameters:category (str) – Type category. Can be any of "object", "class", "property". Defaults to "object".
Raises:MFilesException – If the category supplied doesn’t exist.
Returns:List of dicts with information about the types.
Return type:list
get_value_id(value_name, list_id, owner_ids)

Get the ID of a specific value in a specific value list.

Parameters:
  • value_name (str) – Name of the value list option to look for.
  • list_id (int) – ID of the list to look in.
  • owner_ids (list) – IDs of potential list owners.
Raises:

MFilesException – If the value name can’t be found in the list.

Returns:

ID of value in value list.

Return type:

int

login(server=None, user=None, password=None, vault=None)

Logs in the user to M-Files.

Logs in and prepares the authentication token, ready to be used in http request header as authentication.

Parameters:
  • server (str) – API URL.
  • user (str) – User to login with. If not supplied it will be fetched from environment variable MFILES_USER, if not set it will be fetched using input().
  • password (str) – User password. If not supplied it will be fetched from environment variable MFILES_PASS, if not set it will be fetched using getpass().
  • vault (str) – M-Files vault GUID to connect to.
objects()

Get all object types in the M-Files vault.

post(endpoint, data=None)

General purpose POST method.

Parameters:
  • endpoint (str) – Endpoint on form "path/to/endpoint".
  • data (str) – Data to use in POST request.
Raises:

MFilesException – If request returns status code != 200.

Returns:

Dictionary with request result.

Return type:

dict

properties()

Get all property definitions in the M-Files vault.

put(endpoint, data=None)

General purpose PUT method.

Parameters:
  • endpoint (str) – Endpoint on form "path/to/endpoint".
  • data (str) – Data to use in PUT request.
Raises:

MFilesException – If request returns status code != 200.

Returns:

Dictionary with request result.

Return type:

dict

Perform a quick search in the M-Files vault.

This returns the same results as if the query was performed against the M-Files client search box.

Parameters:query (str) – Search query.
Returns:A list of matching items.
Return type:list
search(query)

Perform a search in the M-Files vault.

Parameters:query (str) – Search query.
Returns:A list of matching items.
Return type:list
set_password(password)

Set the M-Files user password.

set_server(server)

Set the M-Files server API URL.

set_user(user)

Set the M-Files user.

set_vault(vault)

Set the M-Files vault GUID to connect to.

translate_name(name, category='object')

Translate a name into its ID as recognized by the server.

Parameters:
  • name (str) – Name to translate.
  • category (str) – Type category. Can be any of "object", "class", "property". Defaults to "object".
Returns:

ID of name.

Return type:

int

upload_file(file_path, object_type=0, object_class=0, extra_info=None)

Upload a file to M-Files.

Parameters:
  • file_path (str) – Path to file to upload.
  • object_type (str, int) – Object type. If integer, the type will not be attempted to be translated. If string, the type will be transated into the property ID the server expects for the given type.
  • object_class (str, int) – Object class, same translation principle as for object_type.
  • extra_info (dict) – Additional object information.
Raises:

MFilesException – If the file can’t be uploaded.

Returns:

Dictionary with API request result.

Return type:

dict

value_list_items(list_id)

Get items for a specific value list in the M-Files vault.

value_lists()

Get all value lists in the M-Files vault.