{"id":21247110,"url":"https://github.com/alchemyplatform/alchemy-sdk-py","last_synced_at":"2025-07-10T22:32:08.951Z","repository":{"id":65773546,"uuid":"585574519","full_name":"alchemyplatform/alchemy-sdk-py","owner":"alchemyplatform","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-05T18:02:41.000Z","size":445,"stargazers_count":31,"open_issues_count":9,"forks_count":9,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-11-13T18:35:36.924Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alchemyplatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-01-05T14:18:25.000Z","updated_at":"2024-11-05T13:35:59.000Z","dependencies_parsed_at":"2023-12-04T17:37:39.916Z","dependency_job_id":null,"html_url":"https://github.com/alchemyplatform/alchemy-sdk-py","commit_stats":{"total_commits":45,"total_committers":5,"mean_commits":9.0,"dds":"0.19999999999999996","last_synced_commit":"106bfc3b6a2b6acd4c238b43c34a911b611bcf73"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alchemyplatform%2Falchemy-sdk-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alchemyplatform%2Falchemy-sdk-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alchemyplatform%2Falchemy-sdk-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alchemyplatform%2Falchemy-sdk-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alchemyplatform","download_url":"https://codeload.github.com/alchemyplatform/alchemy-sdk-py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225658502,"owners_count":17503667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2024-11-21T02:15:58.422Z","updated_at":"2024-11-21T02:15:58.977Z","avatar_url":"https://github.com/alchemyplatform.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alchemy SDK for Python\nAn Alchemy SDK to use the [Alchemy API](https://www.alchemy.com/).\n\n\u003e❗❗ **THIS LIBRARY IS IN EARLY ALPHA** ❗❗\n\u003e\n\u003e This library is in active development and does not follow semantic versioning. Breaking changes may be introduced at any time. Please use with caution.\n\nThe SDK supports the exact same syntax and functionality of the Web3 `eth`,\nmaking it a 1:1 mapping for anyone using the Web3 `eth` library. However, it adds a\nsignificant amount of improved functionality on top of Web3, such as easy\naccess to Alchemy’s Enhanced and NFT APIs, and quality-of-life improvements\nsuch as automated retries.\n\nThe SDK leverages Alchemy's hardened node infrastructure,\nguaranteeing best-in-class node reliability, scalability, and data correctness,\nand is undergoing active development by Alchemy's engineers.\n\n\n\n\u003e 🙋‍♀️ **FEATURE REQUESTS:**\n\u003e\n\u003e We'd love your thoughts on what would improve your web3 dev process the most! If you have 5 minutes, tell us what you want on our [Feature Request feedback form](https://alchemyapi.typeform.com/sdk-feedback), and we'd love to build it for you.\n\nThe SDK currently supports the following chains:\n\n- **Ethereum**: Mainnet, Goerli\n- **Polygon**: Mainnet, Mumbai\n- **Optimism**: Mainnet, Goerli, Kovan\n- **Arbitrum**: Mainnet, Goerli, Rinkeby\n- **Astar**: Mainnet\n\n\n## Getting started\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install alchemy-sdk.\n\n```bash\npip3 install alchemy-sdk\n```\n\nAfter installing the app, you can then import and use the SDK:\n\n```python\nfrom alchemy import Alchemy, Network\n\n# create Alchemy object using your Alchemy api key, default is \"demo\"\napi_key = \"your_api_key\"\n\n# choose preferred network from Network, default is ETH_MAINNET\nnetwork = Network.ETH_MAINNET\n\n# choose the maximum number of retries to perform, default is 5\nmax_retries = 3\n\n# create Alchemy object\nalchemy = Alchemy(api_key, network, max_retries=max_retries)\n```\n\n\u003e **ℹ️ Creating a unique Alchemy API Key**\n\u003e\n\u003e The public \"demo\" API key may be rate limited based on traffic. To create your own API key, **[sign up for an Alchemy account here](https://alchemy.com/?a=SDKquickstart)** and use the key created on your dashboard for the first app.\n\n## Using the Alchemy SDK\n\nThe Alchemy SDK currently supports 2 different namespaces, including:\n\n- `core`: All web3.eth methods and Alchemy Enhanced API methods\n- `nft`: All Alchemy NFT API methods\n\nIf you are already using web3.eth, you should be simply able to replace the web3.eth object with `alchemy.core` and it should work properly.\n\n\u003e **ℹ️ ENS Name Resolution**\n\u003e\n\u003e The Alchemy SDK supports ENS names (e.g. `vitalik.eth`) for every parameter where you can pass in a Externally Owned Address, or user address (e.g. `0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045`).\n\n```python\nfrom alchemy import Alchemy\nalchemy = Alchemy()\n\n# Access standard Web3 request. Gets latest block hash\nblock_hash = Alchemy.to_hex(alchemy.core.get_block('latest')['hash'])\n\n# Access Alchemy Enhanced API requests. Gets all transaction receipts for a given block hash.\nalchemy.core.get_transaction_receipts(block_hash=block_hash)\n\n# Access the Alchemy NFT API. Gets contract metadata for NFT and gets collection name\ncontract = \"0x01234567bac6ff94d7e4f0ee23119cf848f93245\"\nprint(alchemy.nft.get_contract_metadata(contract).opensea_metadata.collection_name)\n```\n\nThe Alchemy class also supports static methods from Web3 object that streamline the development process:\n - Encoding, Decoding, Hashing: `to_bytes`, `to_int`, `to_hex`, `to_text`, `to_json`, `keccak`\n - Currency Utility: `to_wei`, `from_wei`\n - Address Utility: `is_address`, `is_checksum_address`, `to_checksum_address`\n\n\n## Alchemy Core\n\nThe core namespace contains all commonly-used Web3.eth methods.\n\nIt also includes the majority of Alchemy Enhanced APIs, including:\n\n- `get_token_metadata()`: Get the metadata for a token contract address.\n- `get_token_balances()`: Gets the token balances for an owner given a list of contracts.\n- `get_asset_transfers()`: Get transactions for specific addresses.\n- `get_transaction_receipts()`: Gets all transaction receipts for a given block.\n\n## Alchemy NFT API\n\nThe SDK currently supports the following [NFT API](https://docs.alchemy.com/alchemy/enhanced-apis/nft-api) endpoints\nunder the `alchemy.nft` namespace:\n\n- `get_nft_metadata()`: Get the NFT metadata for an NFT contract address and tokenId.\n- `get_nft_metada_batch()`: Get the NFT metadata for multiple NFT contract addresses/token id pairs.\n- `get_contract_metadata()`: Get the metadata associated with an NFT contract.\n- `get_contract_metadata_batch()`: Get the metadata associated with multiple NFT contracts in a single request.\n- `get_contracts_for_owner()`: Get all NFT contracts that the provided owner address owns.\n- `get_nfts_for_owner()`: Get NFTs for an owner address.\n- `get_nfts_for_contract()`: Get all NFTs for a contract address.\n- `get_owners_for_nft()`: Get all the owners for a given NFT contract address and a particular token ID.\n- `get_owners_for_contract()`: Get all the owners for a given NFT contract address.\n- `get_minted_nfts()`: Get all the NFTs minted by the owner address.\n- `get_transfers_for_owner()`: Get all the NFT transfers for a given owner address.\n- `get_transfers_for_contract()`: Get all the NFT transfers for a given NFT contract address.\n- `verify_nft_ownership()`: Check whether the provided owner address owns the provided NFT contract addresses.\n- `is_spam_contract()`: Check whether the given NFT contract address is a spam contract as defined by Alchemy (see the [NFT API FAQ](https://docs.alchemy.com/alchemy/enhanced-apis/nft-api/nft-api-faq#nft-spam-classification))\n- `get_spam_contracts()`: Returns a list of all spam contracts marked by Alchemy.\n- `refresh_nft_metadata()`: Refresh the cached NFT metadata for a contract address and a single tokenId.\n- `refresh_contract()`: Enqueues the specified contract address to have all token ids' metadata refreshed.\n- `get_floor_price()`: Return the floor prices of a NFT contract by marketplace.\n- `compute_rarity()`: Get the rarity of each attribute of an NFT.\n- `get_nft_sales()`: Returns NFT sales that have happened through on-chain marketplaces.\n- `summarize_nft_attributes()`: Get the summary of attribute prevalence for all NFTs in a contract.\n- `search_contract_metadata()`: Search for a keyword across metadata of all ERC-721 and ERC-1155 smart contracts.\n\n### Pagination\n\nThe Alchemy NFT endpoints return 100 results per page. To get the next page, you can pass in\nthe `page_key` returned by the previous call.\n\n### SDK vs API Differences\n\nThe NFT API in the SDK standardizes response types to reduce developer friction, but note this results in some\ndifferences compared to the Alchemy REST endpoints:\n\n- Methods referencing `Collection` have been renamed to use the name `Contract` for greater accuracy: e.g. `get_nfts_for_contract`.\n- Some methods have different naming that the REST API counterparts in order to provide a consistent API interface (\n  e.g. `get_nfts_for_owner()` is `alchemy_getNfts`, `get_owners_for_nft()` is `alchemy_getOwnersForToken`).\n- SDK standardizes to `omit_metadata` parameter (vs. `withMetadata`).\n- Standardization to `page_key` parameter for pagination (vs. `nextToken`/`startToken`)\n- Empty `token_uri` fields are omitted.\n- Token ID is always normalized to an integer string on `BaseNft` and `Nft`.\n- Some fields omitted in the REST response are included in the SDK response in order to return an `Nft` object.\n- Some fields in the SDK's `Nft` object are named differently than the REST response.\n\n## Usage Examples\n\nBelow are a few usage examples.\n\n### Getting the NFTs owned by an address\n\n```python\nfrom alchemy import Alchemy\nfrom alchemy.nft import NftFilters\n\nalchemy = Alchemy()\n\n# Get how many NFTs an address owns.\nresponse = alchemy.nft.get_nfts_for_owner('vitalik.eth')\nprint(response['total_count'])\n\n# Get all the image urls for all the NFTs an address owns.\nfor nft in response['owned_nfts']:\n    print(nft.image)\n\n# Filter out spam NFTs.\nnfts_without_spam = alchemy.nft.get_nfts_for_owner('vitalik.eth', exclude_filters=[NftFilters.SPAM])\n```\n\n### Getting all the owners of the BAYC NFT\n\n```python\nfrom alchemy import Alchemy\n\nalchemy = Alchemy()\n\n# Bored Ape Yacht Club contract address.\nbayc_address = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D'\n\n# Omit the NFT metadata for smaller payloads.\nresponse = alchemy.nft.get_nfts_for_contract(bayc_address, omit_metadata=True, page_size=5)\nfor nft in response['nfts']:\n    owners = alchemy.nft.get_owners_for_nft(\n        contract_address=nft.contract_address, token_id=nft.token_id\n    )\n    print(f\"owners: {owners}, tokenId: {nft.token_id}\")\n```\n\n### Get all outbound transfers for a provided address\n\n```python\nfrom alchemy import Alchemy\n\nalchemy = Alchemy()\nprint(alchemy.core.get_token_balances('vitalik.eth'))\n```\n\n\n## Questions and Feedback\n\nIf you have any questions, issues, or feedback, please file an issue\non [GitHub](https://github.com/alchemyplatform/alchemy-sdk-py/issues), or drop us a message on\nour [Discord](https://discord.com/channels/735965332958871634/983472322998575174) channel for the SDK.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falchemyplatform%2Falchemy-sdk-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falchemyplatform%2Falchemy-sdk-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falchemyplatform%2Falchemy-sdk-py/lists"}