{"id":8016,"library":"cloudsmith-api","title":"Cloudsmith API Client","description":"The `cloudsmith-api` library is an auto-generated Python client for interacting with the Cloudsmith package management API (version 1). It provides programmatic access to manage repositories, packages, users, and more. As of May 2024, the latest version is 2.0.25, with frequent releases reflecting updates to the underlying OpenAPI specification.","status":"active","version":"2.0.25","language":"en","source_language":"en","source_url":"https://github.com/cloudsmith-io/cloudsmith-api-python","tags":["cloud","devops","package-management","api-client","openapi"],"install":[{"cmd":"pip install cloudsmith-api","lang":"bash","label":"Install Cloudsmith API Client"}],"dependencies":[{"reason":"HTTP client for API requests.","package":"urllib3"},{"reason":"Python 2 and 3 compatibility utilities.","package":"six"},{"reason":"Date and time parsing for API responses.","package":"python-dateutil"},{"reason":"SSL certificates for secure connections.","package":"certifi"}],"imports":[{"note":"The primary module for client configuration and API access.","symbol":"cloudsmith_api","correct":"import cloudsmith_api"},{"note":"Exception class for handling API errors, located in the 'rest' submodule.","wrong":"from cloudsmith_api import ApiException","symbol":"ApiException","correct":"from cloudsmith_api.rest import ApiException"},{"note":"Accessed as `cloudsmith_api.Configuration` for setting up API keys and host.","symbol":"Configuration","correct":"import cloudsmith_api"},{"note":"Accessed as `cloudsmith_api.RepositoriesApi` for repository-related operations.","symbol":"RepositoriesApi","correct":"import cloudsmith_api"}],"quickstart":{"code":"import os\nimport cloudsmith_api\nfrom cloudsmith_api.rest import ApiException\n\n# Configure API key authorization:\nX-Api-Key = os.environ.get('CLOUDSMITH_API_KEY', '')\n\nif not X_Api_Key:\n    print(\"Error: CLOUDSMITH_API_KEY environment variable not set.\")\n    exit(1)\n\nconfiguration = cloudsmith_api.Configuration(api_key={'X-Api-Key': X_Api_Key})\n\n# Enter a context with an instance of the API client\nwith cloudsmith_api.ApiClient(configuration) as api_client:\n    # Create an instance of the API class\n    repositories_api = cloudsmith_api.RepositoriesApi(api_client)\n\n    try:\n        # List repositories\n        print(\"Listing Cloudsmith repositories...\")\n        api_response = repositories_api.repos_list()\n        for repo in api_response.data:\n            print(f\"  - {repo.name} (Slug: {repo.slug}) by {repo.owner}\")\n    except ApiException as e:\n        print(f\"Exception when calling RepositoriesApi->repos_list: {e}\")\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to authenticate using an API key from an environment variable and list all accessible Cloudsmith repositories. Ensure the `CLOUDSMITH_API_KEY` environment variable is set."},"warnings":[{"fix":"Review the official changelog and API documentation for version 2.x.x. Test your application thoroughly after upgrading. Pay attention to changes in model properties and API method parameters.","message":"Major version `2.x.x` of the `cloudsmith-api` client library (released August 2023) introduced potential breaking changes compared to `1.x.x` versions. This was due to an upgrade of the underlying OpenAPI Generator, which can alter method signatures, object structures, and error handling patterns.","severity":"breaking","affected_versions":"1.x.x to 2.x.x"},{"fix":"Always configure your API key as `api_key={'X-Api-Key': 'YOUR_API_KEY'}` within the `cloudsmith_api.Configuration` object. Do not pass the key directly as a string or in other header formats.","message":"API key authentication requires the key to be passed within a dictionary, mapping 'X-Api-Key' to your actual key. Incorrectly formatted authentication can lead to `401 Unauthorized` errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Double-check the `owner` and `repo` slugs for accuracy. These are case-sensitive and must exactly match what is configured in Cloudsmith. Consult the Cloudsmith UI or previous API calls to confirm correct slugs.","message":"Many API endpoints require both an `owner` slug (your organization or user slug) and a `repo` slug (the repository identifier). Misunderstanding these parameters or providing incorrect slugs often results in `404 Not Found` errors.","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":"Verify that the `CLOUDSMITH_API_KEY` environment variable (or wherever you get your key) is correctly set and contains a valid Cloudsmith API key. Ensure the key has the necessary permissions for the API calls being made.","cause":"The provided API key is either missing, invalid, or has insufficient permissions for the requested operation.","error":"cloudsmith_api.rest.ApiException: (401) Reason: Unauthorized"},{"fix":"Check the `owner`, `repo` (and any other identifier slugs) parameters in your API call. Ensure they are correctly spelled and correspond to existing resources in your Cloudsmith account. Remember slugs are case-sensitive.","cause":"The resource (e.g., repository, package) specified in the API call does not exist, or the owner/repository slugs are incorrect.","error":"cloudsmith_api.rest.ApiException: (404) Reason: Not Found"},{"fix":"After importing `cloudsmith_api`, you must first create a `cloudsmith_api.ApiClient` instance (potentially with a `cloudsmith_api.Configuration`). Then, create an API-specific client like `repositories_api = cloudsmith_api.RepositoriesApi(api_client)` before calling methods on it.","cause":"Attempting to access an API client class or function directly from the top-level `cloudsmith_api` module instead of through an instantiated API client.","error":"AttributeError: module 'cloudsmith_api' has no attribute '...' (e.g., 'RepositoriesApi')"}]}