nextcloud

Platypush documentation

nextcloud#

Description#

Plugin to interact with a NextCloud instance.

Configuration#

nextcloud:
  # [Required]
  # URL to the index of your default NextCloud instance.
  url:   # type=str

  # [Required]
  # Default NextCloud username.
  username:   # type=str

  # [Required]
  # Default NextCloud password. If the user has 2FA
  # enabled then you can generate an app password from the personal
  # settings page of your NextCloud instance.
  password:   # type=str

  # [Optional]
  # How often the plugin should poll for new activity
  # events (default: 30 seconds).
  # poll_interval: 30.0  # type=Optional[float]

  # [Optional]
  # How long we should wait for any running
  # threads/processes to stop before exiting (default: 5 seconds).
  # stop_timeout: 5  # type=Optional[float]

  # [Optional]
  # If set to True then the plugin will not monitor
  # for new events. This is useful if you want to run a plugin in
  # stateless mode and only leverage its actions, without triggering any
  # events. Defaults to False.
  # disable_monitor: False  # type=bool

Dependencies#

pip

pip install nextcloud-api-wrapper

Triggered events#

Actions#

Module reference#

class platypush.plugins.nextcloud.ClientConfig(url: str, username: str, password: str)[source]#

Bases: object

Configuration for the NextCloud client.

__init__(url: str, username: str, password: str) None#
class platypush.plugins.nextcloud.NextcloudPlugin(url: str, username: str, password: str, poll_interval: float | None = 30.0, **kwargs)[source]#

Bases: RunnablePlugin

Plugin to interact with a NextCloud instance.

__init__(url: str, username: str, password: str, poll_interval: float | None = 30.0, **kwargs)[source]#
Parameters:
  • url – URL to the index of your default NextCloud instance.

  • username – Default NextCloud username.

  • password – Default NextCloud password. If the user has 2FA enabled then you can generate an app password from the personal settings page of your NextCloud instance.

  • poll_interval – How often the plugin should poll for new activity events (default: 30 seconds).

add_group(group_id: str | int, **server_args)[source]#

Create a new group.

Parameters:
  • group_id – New group unique ID.

  • server_args – Override the default server settings (see _get_client() arguments).

add_to_group(user_id: str, group_id: str, **server_args)[source]#

Add a user to a group.

Parameters:
  • user_id – User ID/name.

  • group_id – Group ID.

  • server_args – Override the default server settings (see _get_client() arguments).

copy(path: str, destination: str, overwrite: bool = False, **server_args)[source]#

Copy a resource to another path.

Parameters:
  • path – Resource path.

  • destination – Destination path.

  • overwrite – Set to True if you want to overwrite any existing file (default: False).

  • server_args – Override the default server settings (see _get_client() arguments).

create_folder(path: str, **server_args)[source]#

Create a folder.

Parameters:
  • path – Path to the folder.

  • server_args – Override the default server settings (see _get_client() arguments).

create_group_folder(name: str, **server_args)[source]#

Create a new group folder.

Parameters:
  • name – Name/path of the folder.

  • server_args – Override the default server settings (see _get_client() arguments).

create_share(path: str, share_type: str, share_with: str | None = None, public_upload: bool = False, password: str | None = None, permissions: List[str] | None = None, **server_args) dict[source]#

Share a file/folder with a user/group or a public link.

Parameters:
  • path – Path to the resource to be shared.

  • share_type

    Share type. Supported values:

    • user

    • group

    • public_link

    • email

    • federated_cloud_share

    • circle

    • talk_conversation

  • share_with – User/group ID, email or conversation ID the resource should be shared with.

  • public_upload – Whether public upload to the shared folder is allowed (default: False).

  • password – Optional password to protect the share.

  • permissions

    Share permissions, as a list including any of the following (default: read):

    • read

    • update

    • create

    • delete

    • share

    • all

  • server_args – Override the default server settings (see _get_client() arguments).

Returns:

The details of the newly created share. Example:

{
  "id": "4",
  "share_type": 3,
  "uid_owner": "your_uid",
  "displayname_owner": "Your Name",
  "permissions": 17,
  "can_edit": true,
  "can_delete": true,
  "stime": 1599691325,
  "parent": null,
  "expiration": null,
  "token": "AbCdEfG0123456789",
  "uid_file_owner": "your_uid",
  "note": "",
  "label": "",
  "displayname_file_owner": "Your Name",
  "path": "/Shared Path",
  "item_type": "folder",
  "mimetype": "httpd/unix-directory",
  "storage_id": "home::your-uid",
  "storage": 2,
  "item_source": 13960,
  "file_source": 13960,
  "file_parent": 6,
  "file_target": "/Shared Path",
  "share_with": null,
  "share_with_displayname": "(Shared link)",
  "password": null,
  "send_password_by_talk": false,
  "url": "https://your-domain/nextcloud/index.php/s/AbCdEfG0123456789",
  "mail_send": 1,
  "hide_download": 0
}

create_subadmin(user_id: str, group_id: str, **server_args)[source]#

Add a user as a subadmin for a group.

Parameters:
  • user_id – User ID/name.

  • group_id – Group ID.

  • server_args – Override the default server settings (see _get_client() arguments).

create_user(user_id: str, password: str, **server_args)[source]#

Create a user.

Parameters:
  • user_id – User ID/name.

  • password – User password

  • server_args – Override the default server settings (see _get_client() arguments).

delete(path: str, **server_args)[source]#

Delete a file or folder.

Parameters:
  • path – Path to the resource.

  • server_args – Override the default server settings (see _get_client() arguments).

delete_group(group_id: str | int, **server_args)[source]#

Delete a group.

Parameters:
  • group_id – Group ID.

  • server_args – Override the default server settings (see _get_client() arguments).

delete_group_folder(folder_id: int | str, **server_args)[source]#

Delete a new group folder.

Parameters:
  • folder_id – Folder ID.

  • server_args – Override the default server settings (see _get_client() arguments).

delete_notification(notification_id: int, **server_args)[source]#

Delete a notification.

Parameters:
  • notification_id – Notification ID.

  • server_args – Override the default server settings (see _get_client() arguments).

delete_notifications(**server_args)[source]#

Delete all notifications for the logged user.

Parameters:

server_args – Override the default server settings (see _get_client() arguments).

delete_share(share_id: int, **server_args)[source]#

Remove the shared state of a resource.

Parameters:
  • share_id – Share ID.

  • server_args – Override the default server settings (see _get_client() arguments).

delete_user(user_id: str, **server_args)[source]#

Delete a user.

Parameters:
  • user_id – User ID/name.

  • server_args – Override the default server settings (see _get_client() arguments).

disable_app(app_id: str | int, **server_args)[source]#

Disable an app.

Parameters:
  • app_id – App ID.

  • server_args – Override the default server settings (see _get_client() arguments).

disable_user(user_id: str, **server_args)[source]#

Disable a user.

Parameters:
  • user_id – User ID/name.

  • server_args – Override the default server settings (see _get_client() arguments).

download_file(remote_path: str, local_path: str, **server_args)[source]#

Download a file.

Parameters:
  • remote_path – Path to the remote resource.

  • local_path – Path to the local folder.

  • server_args – Override the default server settings (see _get_client() arguments).

edit_user(user_id: str, properties: Dict[str, str], **server_args)[source]#

Update a set of properties of a user.

Parameters:
  • user_id – User ID/name.

  • properties – Key-value pair of user attributes to be edited.

  • server_args – Override the default server settings (see _get_client() arguments).

enable_app(app_id: str | int, **server_args)[source]#

Enable an app.

Parameters:
  • app_id – App ID.

  • server_args – Override the default server settings (see _get_client() arguments).

enable_user(user_id: str, **server_args)[source]#

Enable a user.

Parameters:
  • user_id – User ID/name.

  • server_args – Override the default server settings (see _get_client() arguments).

get_activities(since: str | None = None, limit: int | None = 25, object_type: str | None = None, object_id: int | None = None, sort: str = 'desc', **server_args) List[dict][source]#

Get the list of recent activities on an instance.

Parameters:
  • since – Only return the activities that have occurred since the specified ID.

  • limit – Maximum number of activities to be returned (default: 25).

  • object_type – Filter by object type.

  • object_id – Only get the activities related to a specific object_id.

  • sort – Sort mode, asc for ascending, desc for descending (default: desc).

  • server_args – Override the default server settings (see _get_client() arguments).

Returns:

The list of selected activities.

get_app(app_id: str | int, **server_args) dict[source]#

Provides information about an application.

Parameters:
  • app_id – App ID.

  • server_args – Override the default server settings (see _get_client() arguments).

get_apps(**server_args) List[str][source]#

Get the list of apps installed on a NextCloud instance.

Parameters:

server_args – Override the default server settings (see _get_client() arguments).

Returns:

The list of installed apps as strings.

get_capabilities(**server_args) dict[source]#

Returns the capabilities of the server.

Parameters:

server_args – Override the default server settings (see _get_client() arguments).

Returns:

Server capabilities. Example:

{
  "version": {
    "major": 27,
    "minor": 1,
    "micro": 5,
    "string": "27.1.5",
    "edition": "",
    "extendedSupport": false
  },
  "capabilities": {
    "core": {
      "pollinterval": 60,
      "webdav-root": "remote.php/webdav",
    },
    "files": {
      "bigfilechunking": true,
      "blacklisted_files": [
        ".htaccess"
      ],
      "comments": true,
      "undelete": true,
      "versioning": true,
      "version_labeling": true,
      "version_deletion": true
    },
    "activity": {
      "apiv2": [
        "filters",
        "filters-api",
        "previews",
        "rich-strings"
      ]
    },
    "notifications": {
      "ocs-endpoints": [
        "list",
        "get",
        "delete",
        "delete-all",
        "icons",
        "rich-strings",
        "action-web",
        "user-status",
        "exists"
      ],
      "push": [
        "devices",
        "object-data",
        "delete"
      ],
      "admin-notifications": [
        "ocs",
        "cli"
      ]
    },
    "theming": {
      "name": "Nextcloud",
      "url": "https://nextcloud.com",
      "slogan": "a safe home for all your data",
      "color": "#1F5C98",
      "color-text": "#ffffff",
      "color-element": "#1F5C98",
      "color-element-bright": "#1F5C98",
      "color-element-dark": "#1F5C98",
      "logo": "https://cloud.example.com/core/img/logo/logo.svg?v=0",
      "background": "#1F5C98",
      "background-plain": true,
      "background-default": true,
      "logoheader": "https://cloud.example.com/core/img/logo/logo.svg?v=0",
      "favicon": "https://cloud.example.com/core/img/logo/logo.svg?v=0"
    },
    "user_status": {
      "enabled": true,
      "restore": true,
      "supports_emoji": true
    },
  }
}

get_group(group_id: str | int, **server_args) dict[source]#

Get the information of a group.

Parameters:
  • group_id – Group ID.

  • server_args – Override the default server settings (see _get_client() arguments).

get_group_folder(folder_id: int | str, **server_args) dict[source]#

Get a new group folder.

Parameters:
  • folder_id – Folder ID.

  • server_args – Override the default server settings (see _get_client() arguments).

get_group_folders(**server_args) List[source]#

Get the list new group folder.

Parameters:

server_args – Override the default server settings (see _get_client() arguments).

get_groups(search: str | None = None, limit: int | None = None, offset: int | None = None, **server_args) List[str][source]#

Search for groups.

Parameters:
  • search – Search for groups matching the specified substring.

  • limit – Maximum number of returned entries.

  • offset – Start offset.

  • server_args – Override the default server settings (see _get_client() arguments).

get_notification(notification_id: int, **server_args) dict[source]#

Get the content of a notification.

Parameters:
  • notification_id – Notification ID.

  • server_args – Override the default server settings (see _get_client() arguments).

Returns:

Notification details. Example:

{
  "notification_id": 1234,
  "app": "updatenotification",
  "user": "username",
  "datetime": "2024-01-01T19:00:00+00:00",
  "object_type": "side_menu",
  "object_id": "1.2.3",
  "subject": "Update for MyApp to version 1.2.3 is available.",
  "message": "",
  "link": "https://cloud.example.com/index.php/settings/apps/updates#myapp",
  "subjectRich": "Update for {app} to version 1.2.3 is available.",
  "subjectRichParameters": {
    "app": {
      "type": "app",
      "id": "myapp",
      "name": "MyApp"
    }
  },
  "messageRich": "",
  "messageRichParameters": [],
  "icon": "https://cloud.example.com/apps/updatenotification/img/notification.svg",
  "shouldNotify": true,
  "actions": []
}

get_notifications(**server_args) List[dict][source]#

Get the list of notifications for the logged user.

Parameters:

server_args – Override the default server settings (see _get_client() arguments).

Returns:

A list of notifications. Example:

[
  {
    "notification_id": 1234,
    "app": "updatenotification",
    "user": "username",
    "datetime": "2024-01-01T19:00:00+00:00",
    "object_type": "side_menu",
    "object_id": "1.2.3",
    "subject": "Update for MyApp to version 1.2.3 is available.",
    "message": "",
    "link": "https://cloud.example.com/index.php/settings/apps/updates#myapp",
    "subjectRich": "Update for {app} to version 1.2.3 is available.",
    "subjectRichParameters": {
      "app": {
        "type": "app",
        "id": "myapp",
        "name": "MyApp"
      }
    },
    "messageRich": "",
    "messageRichParameters": [],
    "icon": "https://cloud.example.com/apps/updatenotification/img/notification.svg",
    "shouldNotify": true,
    "actions": []
  }
]

get_share(share_id: int, **server_args) dict[source]#

Get the information of a shared resource.

Parameters:
  • share_id – Share ID.

  • server_args – Override the default server settings (see _get_client() arguments).

Returns:

The details of the share. Example:

{
  "id": "4",
  "share_type": 3,
  "uid_owner": "your_uid",
  "displayname_owner": "Your Name",
  "permissions": 17,
  "can_edit": true,
  "can_delete": true,
  "stime": 1599691325,
  "parent": null,
  "expiration": null,
  "token": "AbCdEfG0123456789",
  "uid_file_owner": "your_uid",
  "note": "",
  "label": "",
  "displayname_file_owner": "Your Name",
  "path": "/Shared Path",
  "item_type": "folder",
  "mimetype": "httpd/unix-directory",
  "storage_id": "home::your-uid",
  "storage": 2,
  "item_source": 13960,
  "file_source": 13960,
  "file_parent": 6,
  "file_target": "/Shared Path",
  "share_with": null,
  "share_with_displayname": "(Shared link)",
  "password": null,
  "send_password_by_talk": false,
  "url": "https://your-domain/nextcloud/index.php/s/AbCdEfG0123456789",
  "mail_send": 1,
  "hide_download": 0
}

get_shares(**server_args) List[dict][source]#

Get the list of shares available on the server.

Parameters:

server_args – Override the default server settings (see _get_client() arguments).

Returns:

List of available shares. Example:

[
    {
      "id": "4",
      "share_type": 3,
      "uid_owner": "your_uid",
      "displayname_owner": "Your Name",
      "permissions": 17,
      "can_edit": true,
      "can_delete": true,
      "stime": 1599691325,
      "parent": null,
      "expiration": null,
      "token": "AbCdEfG0123456789",
      "uid_file_owner": "your_uid",
      "note": "",
      "label": "",
      "displayname_file_owner": "Your Name",
      "path": "/Shared Path",
      "item_type": "folder",
      "mimetype": "httpd/unix-directory",
      "storage_id": "home::your-uid",
      "storage": 2,
      "item_source": 13960,
      "file_source": 13960,
      "file_parent": 6,
      "file_target": "/Shared Path",
      "share_with": null,
      "share_with_displayname": "(Shared link)",
      "password": null,
      "send_password_by_talk": false,
      "url": "https://your-domain/nextcloud/index.php/s/AbCdEfG0123456789",
      "mail_send": 1,
      "hide_download": 0
    }
]

get_subadmin_groups(user_id: str, **server_args) List[str][source]#

Get the groups where a given user is subadmin.

Parameters:
  • user_id – User ID/name.

  • server_args – Override the default server settings (see _get_client() arguments).

Returns:

List of matched groups as strings.

get_user(user_id: str, **server_args) dict[source]#

Get the details of a user.

Parameters:
  • user_id – User ID/name.

  • server_args – Override the default server settings (see _get_client() arguments).

Returns:

User details. Example:

{
  "enabled": true,
  "storageLocation": "/mnt/hd/nextcloud/user",
  "id": "user",
  "lastLogin": 1599693750000,
  "backend": "Database",
  "subadmin": [],
  "quota": {
    "free": 6869434515456,
    "used": 1836924441,
    "total": 6871271439897,
    "relative": 0.03,
    "quota": -3
  },
  "email": "info@yourdomain.com",
  "displayname": "Your Name",
  "phone": "+1234567890",
  "address": "",
  "website": "https://yourdomain.com",
  "twitter": "@You",
  "groups": [
    "admin"
  ],
  "language": "en",
  "locale": "",
  "backendCapabilities": {
    "setDisplayName": true,
    "setPassword": true
  }
}

get_users(search: str | None = None, limit: int | None = None, offset: int | None = None, **server_args) List[str][source]#

Get the list of users matching some search criteria.

Parameters:
  • search – Return users matching the provided string.

  • limit – Maximum number of results to be returned (default: no limit).

  • offset – Search results offset (default: None).

Returns:

List of the matched user IDs. Example:

[
    {
      "enabled": true,
      "storageLocation": "/mnt/hd/nextcloud/user",
      "id": "user",
      "lastLogin": 1599693750000,
      "backend": "Database",
      "subadmin": [],
      "quota": {
        "free": 6869434515456,
        "used": 1836924441,
        "total": 6871271439897,
        "relative": 0.03,
        "quota": -3
      },
      "email": "info@yourdomain.com",
      "displayname": "Your Name",
      "phone": "+1234567890",
      "address": "",
      "website": "https://yourdomain.com",
      "twitter": "@You",
      "groups": [
        "admin"
      ],
      "language": "en",
      "locale": "",
      "backendCapabilities": {
        "setDisplayName": true,
        "setPassword": true
      }
    }
]

grant_access_to_group_folder(folder_id: int | str, group_id: str, **server_args)[source]#

Grant access to a group folder to a given group.

Parameters:
  • folder_id – Folder ID.

  • group_id – Group ID.

  • server_args – Override the default server settings (see _get_client() arguments).

list(path: str, depth: int = 1, all_properties: bool = False, **server_args) List[dict][source]#

List the content of a folder on the NextCloud instance.

Parameters:
  • path – Remote path.

  • depth – Search depth (default: 1).

  • all_properties – Return all the file properties available (default: False).

  • server_args – Override the default server settings (see _get_client() arguments).

list_favorites(path: str | None = None, **server_args) List[dict][source]#

List the favorite items for a user.

Parameters:
  • path – Return only the favorites under this path.

  • server_args – Override the default server settings (see _get_client() arguments).

main()[source]#

Implementation of the main loop of the plugin.

mark_favorite(path: str | None = None, **server_args)[source]#

Add a path to a user’s favorites.

Parameters:
  • path – Resource path.

  • server_args – Override the default server settings (see _get_client() arguments).

mkdir(path: str, **server_args)[source]#

Alias for create_folder().

Parameters:
  • path – Path to the folder.

  • server_args – Override the default server settings (see _get_client() arguments).

move(path: str, destination: str, overwrite: bool = False, **server_args)[source]#

Move a resource to another path.

Parameters:
  • path – Resource path.

  • destination – Destination path.

  • overwrite – Set to True if you want to overwrite any existing file (default: False).

  • server_args – Override the default server settings (see _get_client() arguments).

remove_from_group(user_id: str, group_id: str, **server_args)[source]#

Remove a user from a group.

Parameters:
  • user_id – User ID/name.

  • group_id – Group ID.

  • server_args – Override the default server settings (see _get_client() arguments).

remove_subadmin(user_id: str, group_id: str, **server_args)[source]#

Remove a user as a subadmin from a group.

Parameters:
  • user_id – User ID/name.

  • group_id – Group ID.

  • server_args – Override the default server settings (see _get_client() arguments).

rename_group_folder(folder_id: int | str, new_name: str, **server_args)[source]#

Rename a group folder.

Parameters:
  • folder_id – Folder ID.

  • new_name – New folder name.

  • server_args – Override the default server settings (see _get_client() arguments).

revoke_access_to_group_folder(folder_id: int | str, group_id: str, **server_args)[source]#

Revoke access to a group folder to a given group.

Parameters:
  • folder_id – Folder ID.

  • group_id – Group ID.

  • server_args – Override the default server settings (see _get_client() arguments).

set_group_folder_permissions(folder_id: int | str, group_id: str, permissions: List[str], **server_args)[source]#

Set the permissions on a folder for a group.

Parameters:
  • folder_id – Folder ID.

  • group_id – Group ID.

  • permissions

    New permissions, as a list including any of the following:

    • read

    • update

    • create

    • delete

    • share

    • all

  • server_args – Override the default server settings (see _get_client() arguments).

set_group_folder_quota(folder_id: int | str, quota: int | None, **server_args)[source]#

Set the quota of a group folder.

Parameters:
  • folder_id – Folder ID.

  • quota – Quota in bytes - set None for unlimited.

  • server_args – Override the default server settings (see _get_client() arguments).

start()#

Start the plugin.

stop()#

Stop the plugin.

update_share(share_id: int, public_upload: bool | None = None, password: str | None = None, permissions: List[str] | None = None, expire_date: str | None = None, **server_args)[source]#

Update the permissions of a shared resource.

Parameters:
  • share_id – Share ID.

  • public_upload – Whether public upload to the shared folder is allowed (default: False).

  • password – Optional password to protect the share.

  • permissions

    Share permissions, as a list including any of the following (default: read):

    • read

    • update

    • create

    • delete

    • share

    • all

  • expire_date – Share expiration date, in the format YYYY-MM-DD.

  • server_args – Override the default server settings (see _get_client() arguments).

upload_file(remote_path: str, local_path: str | None = None, content: str | None = None, timestamp: datetime | str | int | None = None, **server_args)[source]#

Upload a file.

Parameters:
  • remote_path – Path to the remote resource.

  • local_path – If set, identifies the path to the local file to be uploaded.

  • content – If set, create a new file with this content instead of uploading an existing file.

  • timestamp – File timestamp. If not specified it will be retrieved from the file info or set to now if content is specified.

  • server_args – Override the default server settings (see _get_client() arguments).

wait_stop(timeout=None)#

Wait until a stop event is received.

class platypush.plugins.nextcloud.Permission(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntEnum

Enumerates the permissions that can be granted to a user/group on a resource.

__init__(*args, **kwds)#
as_integer_ratio()#

Return a pair of integers, whose ratio is equal to the original int.

The ratio is in lowest terms and has a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()#

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()#

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()#

Returns self, the complex conjugate of any int.

denominator#

the denominator of a rational number in lowest terms

from_bytes(byteorder='big', *, signed=False)#

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

imag#

the imaginary part of a complex number

is_integer()#

Returns True. Exists for duck type compatibility with float.is_integer.

numerator#

the numerator of a rational number in lowest terms

real#

the real part of a complex number

to_bytes(length=1, byteorder='big', *, signed=False)#

Return an array of bytes representing an integer.

length

Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

class platypush.plugins.nextcloud.ShareType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntEnum

Enumerates the types of shares that can be created.

__init__(*args, **kwds)#
as_integer_ratio()#

Return a pair of integers, whose ratio is equal to the original int.

The ratio is in lowest terms and has a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()#

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()#

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()#

Returns self, the complex conjugate of any int.

denominator#

the denominator of a rational number in lowest terms

from_bytes(byteorder='big', *, signed=False)#

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

imag#

the imaginary part of a complex number

is_integer()#

Returns True. Exists for duck type compatibility with float.is_integer.

numerator#

the numerator of a rational number in lowest terms

real#

the real part of a complex number

to_bytes(length=1, byteorder='big', *, signed=False)#

Return an array of bytes representing an integer.

length

Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.