{"id":41464119,"url":"https://github.com/coinbase-samples/prime-sdk-py","last_synced_at":"2026-01-23T16:18:03.717Z","repository":{"id":253654595,"uuid":"835269631","full_name":"coinbase-samples/prime-sdk-py","owner":"coinbase-samples","description":"Sample Python SDK for the Coinbase Prime REST APIs","archived":false,"fork":false,"pushed_at":"2026-01-14T16:02:43.000Z","size":300,"stargazers_count":12,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-01-14T19:20:34.302Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.cdp.coinbase.com/prime/reference/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coinbase-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-07-29T13:47:57.000Z","updated_at":"2026-01-14T15:58:26.000Z","dependencies_parsed_at":"2025-01-30T01:24:23.035Z","dependency_job_id":"7132039e-28a2-4a9e-ab60-a4ed90f1bc99","html_url":"https://github.com/coinbase-samples/prime-sdk-py","commit_stats":null,"previous_names":["coinbase-samples/prime-sdk-py"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/coinbase-samples/prime-sdk-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase-samples%2Fprime-sdk-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase-samples%2Fprime-sdk-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase-samples%2Fprime-sdk-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase-samples%2Fprime-sdk-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coinbase-samples","download_url":"https://codeload.github.com/coinbase-samples/prime-sdk-py/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase-samples%2Fprime-sdk-py/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28695529,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T15:57:05.722Z","status":"ssl_error","status_checked_at":"2026-01-23T15:56:27.656Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-23T16:17:59.150Z","updated_at":"2026-01-23T16:18:03.683Z","avatar_url":"https://github.com/coinbase-samples.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prime Python SDK README\n\n## Overview\n\nThe *Prime Python SDK* is a sample library that demonstrates the usage of the [Coinbase Prime](https://prime.coinbase.com/) API via its [REST APIs](https://docs.cdp.coinbase.com/prime/reference). This SDK provides a structured way to integrate Coinbase Prime functionalities into your Python applications.\n\n## Installation\n\n### From PyPI (Recommended)\n\n```bash\npip install prime-sdk-py\n```\n\n### From Source\n\n```bash\ngit clone https://github.com/coinbase-samples/prime-sdk-py.git\ncd prime-sdk-py\npip install -e .\n```\n\n## License\n\nThe *Prime Python SDK* sample library is free and open source and released under the [Apache License, Version 2.0](LICENSE).\n\nThe application and code are only available for demonstration purposes.\n\n## Usage\n\n### Setting Up Credentials\n\nTo use the *Prime Python SDK*, initialize the [Credentials](prime_sdk/credentials.py) class with your Prime API credentials. This class is designed to facilitate the secure handling of sensitive information required to authenticate API requests.\n\nEnsure that your API credentials are stored securely and are not hard-coded directly in your source code. The Credentials class supports creating credentials from a JSON string or directly from environment variables, providing flexibility and enhancing security.\n\n#### Example Initialization:\n```python\nfrom prime_sdk.credentials import Credentials\n\ncredentials = Credentials.from_env()\n```\n\n#### Environment Variable Format\n\nThe SDK supports two formats for credentials configuration:\n\n##### New Format\n\nSet separate environment variables for better security separation:\n\n```bash\nexport PRIME_CREDENTIALS='{\n  \"accessKey\": \"your-access-key\",\n  \"passphrase\": \"your-passphrase\", \n  \"signingKey\": \"your-signing-key\",\n  \"svcAccountId\": \"your-service-account-id\"\n}'\n\nexport PRIME_PORTFOLIO_ID=\"your-portfolio-id\"\nexport PRIME_ENTITY_ID=\"your-entity-id\"\n```\n\n##### Legacy Format (Backwards Compatible)\n\nAll credentials in a single environment variable:\n\n```bash\nexport PRIME_CREDENTIALS='{\n  \"accessKey\": \"your-access-key\",\n  \"passphrase\": \"your-passphrase\",\n  \"signingKey\": \"your-signing-key\", \n  \"portfolioId\": \"your-portfolio-id\",\n  \"svcAccountId\": \"your-service-account-id\",\n  \"entityId\": \"your-entity-id\"\n}'\n```\n\nThe SDK will automatically detect which format you're using. If `PRIME_PORTFOLIO_ID` and `PRIME_ENTITY_ID` are set, it will use the new format; otherwise, it falls back to the legacy format.\n\n### Obtaining API Credentials \n\nCoinbase Prime API credentials can be created in the Prime web console under Settings -\u003e APIs. While not immediately necessary for most endpoints, your entity ID can be retrieved by calling [List Portfolios](https://docs.cdp.coinbase.com/prime/reference/primerestapi_getportfolios).\n\n### Making API Calls\n\nThe SDK is organized into service modules that group related functionality. Each service provides methods for specific API operations.\n\n#### Service-Based Architecture\n\nThe SDK uses a service-based architecture where each domain (portfolios, orders, transactions, etc.) has its own service class:\n\n```python\nfrom prime_sdk.credentials import Credentials\nfrom prime_sdk.client import Client\nfrom prime_sdk.services.portfolios import PortfoliosService, ListPortfoliosRequest\n\n# Initialize credentials and client\ncredentials = Credentials.from_env(\"PRIME_CREDENTIALS\")\nclient = Client(credentials)\n\n# Create the service\nportfolios_service = PortfoliosService(client)\n\n# Make the API call\nrequest = ListPortfoliosRequest()\ntry:\n    response = portfolios_service.list_portfolios(request)\n    print(response)\nexcept Exception as e:\n    print(f\"Failed to list portfolios: {e}\")\n```\n\n#### Available Services\n\nThe SDK provides the following services:\n\n- **PortfoliosService** - Portfolio management (`prime_sdk.services.portfolios`)\n- **OrdersService** - Order management (`prime_sdk.services.orders`) \n- **TransactionsService** - Transaction operations (`prime_sdk.services.transactions`)\n- **WalletsService** - Wallet management (`prime_sdk.services.wallets`)\n- **ActivitiesService** - Activity tracking (`prime_sdk.services.activities`)\n- **AssetsService** - Asset information (`prime_sdk.services.assets`)\n- **BalancesService** - Balance queries (`prime_sdk.services.balances`)\n- **UsersService** - User management (`prime_sdk.services.users`)\n- **ProductsService** - Product information (`prime_sdk.services.products`)\n- **StakingService** - Staking operations (`prime_sdk.services.staking`)\n\n#### Complete Example: Creating a Transfer\n\n```python\nfrom prime_sdk.credentials import Credentials\nfrom prime_sdk.client import Client\nfrom prime_sdk.services.transactions import (\n    TransactionsService, \n    CreateTransferRequest\n)\n\ndef main():\n    # Initialize credentials and client\n    credentials = Credentials.from_env(\"PRIME_CREDENTIALS\")\n    client = Client(credentials)\n    \n    # Create the transactions service\n    transactions_service = TransactionsService(client)\n    \n    # Create a transfer request\n    request = CreateTransferRequest(\n        portfolio_id=\"your-portfolio-id\",\n        wallet_id=\"your-wallet-id\",\n        amount=\"0.01\",\n        destination=\"your-destination-wallet-id\",\n        currency_symbol=\"ETH\",\n        idempotency_key=str(uuid.uuid4())\n    )\n    \n    try:\n        response = transactions_service.create_transfer(request)\n        print(f\"Transfer created: {response}\")\n    except Exception as e:\n        print(f\"Failed to create transfer: {e}\")\n\nif __name__ == \"__main__\":\n    main()\n```\n\n## Services Client (Recommended)\n\nFor most use cases, we recommend using the **PrimeServicesClient** which provides a more convenient way to access all Prime services through a single client interface. This approach eliminates the need to manually create individual service instances.\n\n### Quick Start with Services Client\n\n```python\nfrom prime_sdk.client_services import PrimeServicesClient\n\n# Create client from environment variables\nclient = PrimeServicesClient.from_env()\n\n# Access any service directly\nportfolios = client.portfolios.list_portfolios(request)\norders = client.orders.create_order(request)\ntransactions = client.transactions.create_transfer(request)\n```\n\n### Complete Example with Services Client\n\n```python\nimport os\nfrom prime_sdk.client_services import PrimeServicesClient\nfrom prime_sdk.services.transactions import CreateTransferRequest\n\ndef main():\n    # Create client from environment\n    client = PrimeServicesClient.from_env()\n    \n    # Create transfer request\n    request = CreateTransferRequest(\n        portfolio_id=\"your-portfolio_id\",\n        wallet_id=\"your-wallet-id\", \n        amount=\"0.01\",\n        destination=\"your-destination-wallet-id\",\n        currency_symbol=\"USD\",\n        idempotency_key=str(uuid.uuid4())\n    )\n    \n    try:\n        # Use the services client - no need to create individual services\n        response = client.transactions.create_transfer(request)\n        print(f\"Transfer created: {response}\")\n    except Exception as e:\n        print(f\"Failed to create transfer: {e}\")\n\nif __name__ == \"__main__\":\n    main()\n```\n\n### Services Client vs Individual Services\n\n**Use Services Client when:**\n- Building applications that use multiple Prime services\n- You want a simple, unified interface\n- You prefer convenience over fine-grained control\n\n**Use Individual Services when:**\n- You only need one or two specific services\n- You want explicit control over service instantiation\n- You're building a minimal application with specific performance requirements\n\n### Supported Versions\nThe SDK is tested and confirmed to work with Python version 3.7 and newer.\n\n## Local Development\n\n### Making Changes to the SDK\n\nIf you need to make modifications to the SDK for your specific use case, follow these steps:\n\n#### 1. Clone and Setup\n\n```bash\ngit clone https://github.com/coinbase-samples/prime-sdk-py.git\ncd prime-sdk-py\n```\n\n#### 2. Install in Development Mode\n\n```bash\npip install -e .\n```\n\nThis installs the SDK in \"editable\" mode, meaning changes to the source code will be immediately reflected without reinstallation.\n\n#### 3. Running Tests\n\n```bash\n# Install test dependencies\npip install pytest\n\n# Run tests\npytest tests/\n```\n\n#### 4. Code Structure\n\nThe SDK follows this structure:\n\n```\nprime_sdk/\n├── credentials.py          # Authentication handling\n├── client.py              # HTTP client\n├── base_response.py       # Base response classes\n├── utils.py               # Utility functions\n├── enums.py               # Common enumerations\n└── services/              # Service modules\n    ├── portfolios/        # Portfolio operations\n    ├── orders/            # Order management\n    ├── transactions/      # Transaction operations\n    ├── wallets/           # Wallet management\n    └── ...                # Other services\n```\n\nEach service directory contains:\n- `service.py` - The main service class with API methods\n- Individual request/response modules (e.g., `list_portfolios.py`)\n- `__init__.py` - Exports for the service","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoinbase-samples%2Fprime-sdk-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoinbase-samples%2Fprime-sdk-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoinbase-samples%2Fprime-sdk-py/lists"}