{"id":7710,"library":"sendsafely","title":"SendSafely Python Client API","description":"The SendSafely Client API allows programmatic access to SendSafely, providing a layer of abstraction over the complex REST API for secure data transfer capabilities within Python applications. It handles cryptographic details, file segmentation, and server authentication. The current version is 1.0.9.6, and the library appears to be actively maintained with frequent point releases.","status":"active","version":"1.0.9.6","language":"en","source_language":"en","source_url":"https://github.com/SendSafely/Python-Client-API","tags":["security","file transfer","encryption","api client","data exchange"],"install":[{"cmd":"pip install sendsafely","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for making HTTP requests to the SendSafely REST API.","package":"requests","optional":false},{"reason":"Crucial for handling OpenPGP encryption and decryption operations within the client. A specific version is pinned for compatibility.","package":"pgpy==0.5.2","optional":false},{"reason":"Provides cryptographic primitives used in secure operations. A specific version is pinned for compatibility.","package":"cryptography==3.4.7","optional":false},{"reason":"Python 2 and 3 compatibility utilities.","package":"six==1.15.0","optional":false},{"reason":"Internationalized Domain Names in Applications (IDNA) support.","package":"idna==2.10","optional":false},{"reason":"Provides Mozilla's carefully curated collection of Root Certificates for validating the trustworthiness of SSL certificates.","package":"certifi==2021.5.30","optional":false},{"reason":"Universal character encoding detector.","package":"chardet==4.0.0","optional":false},{"reason":"HTTP client library, often a dependency of `requests`.","package":"urllib3==1.26.5","optional":false},{"reason":"Python RSA implementation.","package":"rsa==4.7.2","optional":false},{"reason":"ASN.1 types and codecs.","package":"pyasn1==0.4.8","optional":false}],"imports":[{"note":"The primary classes for interacting with the SendSafely API are 'SendSafely' for authentication and general API handling, and 'Package' for managing secure packages.","symbol":"SendSafely","correct":"from sendsafely import SendSafely, Package"},{"note":"The 'Package' object should be instantiated by passing a 'SendSafely' instance to its constructor, not directly or without arguments.","wrong":"package = sendsafely.Package()","symbol":"Package","correct":"from sendsafely import SendSafely, Package"}],"quickstart":{"code":"import os\nfrom sendsafely import SendSafely, Package\n\n# Retrieve credentials from environment variables for security\nBASE_URL = os.environ.get('SENDSAFELY_BASE_URL', 'https://your-company.sendsafely.com')\nAPI_KEY = os.environ.get('SENDSAFELY_API_KEY', 'YOUR_API_KEY')\nAPI_SECRET = os.environ.get('SENDSAFELY_API_SECRET', 'YOUR_API_SECRET')\nRECIPIENT_EMAIL = os.environ.get('SENDSAFELY_RECIPIENT_EMAIL', 'user@example.com')\n\nif not all([BASE_URL, API_KEY, API_SECRET, RECIPIENT_EMAIL]):\n    print(\"Please set SENDSAFELY_BASE_URL, SENDSAFELY_API_KEY, SENDSAFELY_API_SECRET, and SENDSAFELY_RECIPIENT_EMAIL environment variables.\")\n    exit(1)\n\ntry:\n    # Create a SendSafely instance object for authentication\n    sendsafely_client = SendSafely(BASE_URL, API_KEY, API_SECRET)\n\n    # Create a new package\n    package = Package(sendsafely_client)\n\n    # Add a secure message to the package\n    package.encrypt_and_upload_message(\"Hello this is a secure message from Python.\")\n\n    # Add a recipient to the package\n    package.add_recipient(RECIPIENT_EMAIL)\n\n    # Finalize the package to generate the secure link\n    response = package.finalize()\n\n    if response and response.get('secureLink'):\n        print(f\"Secure Package Link: {response['secureLink']}\")\n    else:\n        print(\"Failed to finalize package or retrieve secure link.\")\n        print(response)\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the SendSafely client, create a new secure package, add an encrypted message, specify a recipient, and finalize the package to obtain a secure download link. Ensure your `BASE_URL`, `API_KEY`, and `API_SECRET` are obtained from your SendSafely profile."},"warnings":[{"fix":"Ensure you are using the latest version of the `sendsafely` library (1.0.9.6 or newer) which includes a patch to resolve this Python 3.13 compatibility issue.","message":"The `sendsafely` library (specifically its `pgpy` dependency) encountered a `ModuleNotFoundError: No module named 'imghdr'` when run on Python 3.13 due to the removal of `imghdr` from the standard library.","severity":"breaking","affected_versions":"Potentially all versions before a patch for Python 3.13. The issue was reported and subsequently fixed."},{"fix":"Verify your SendSafely subscription level if encountering unexpected API limitations or feature unavailability. Contact SendSafely support for enterprise access.","message":"Full access to all SendSafely API features, especially those for enterprise search and advanced workflows (e.g., SendSafely Actions), may require a SendSafely Enterprise subscription. Functionality can be limited for other account types.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always prefer using the `sendsafely` Python Client API for secure file transfers and package management unless you have a specific need and expertise to implement the underlying cryptographic protocols correctly via the raw REST API.","message":"Directly interacting with the SendSafely REST API requires manual implementation of complex cryptographic operations (e.g., PGP encryption, key generation, timestamp and signature formatting). The Python Client API handles these complexities automatically.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Generate dedicated API Keys and Secrets from your SendSafely account's profile settings. Do not attempt to use regular username/password for API authentication.","message":"API Keys and API Secrets for authentication must be generated from the 'API Keys' section of your profile page when logged into your SendSafely portal. These credentials are distinct from user login credentials and are essential for programmatic access.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Upgrade the `sendsafely` library to version 1.0.9.6 or later, which contains a fix for Python 3.13 compatibility.","cause":"The `imghdr` module, previously used by the `pgpy` dependency, was removed from the Python standard library in Python 3.13.","error":"ModuleNotFoundError: No module named 'imghdr'"},{"fix":"Double-check your `BASE_URL`, `API_KEY`, and `API_SECRET` values. Ensure they are correct and have the necessary permissions for the operations you are performing. Verify the recipient email if applicable. Generate new credentials if unsure.","cause":"This usually indicates incorrect or missing `API_KEY`, `API_SECRET`, or an invalid `BASE_URL` during client initialization. It can also occur if the API key lacks necessary permissions or if a recipient is not authorized for a package.","error":"sendsafely.exceptions.APIError: {'errorCode': 401, 'message': 'Unauthorized'}"},{"fix":"Verify your internet connection and that the `BASE_URL` is correct and accessible. Ensure no firewalls or proxies are blocking the connection. If the URL is correct, the SendSafely service might be temporarily unavailable. Consider adding retry logic with exponential backoff for transient network issues.","cause":"This error often points to network connectivity issues, an incorrect `BASE_URL`, or problems with the SendSafely server being unreachable or refusing the connection.","error":"requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))"},{"fix":"Instantiate `Package` by providing an initialized `SendSafely` object: `package = Package(sendsafely_client)`.","cause":"The `Package` class constructor requires an instance of the `SendSafely` client to be passed as its first argument (`sendsafely_instance`).","error":"package = sendsafely.Package(sendsafely_client) Argument missing: 'sendsafely_instance'"}]}