Package: transpose-data
Welcome to the Transpose Python SDKA modern python wrapper for the Transpose API Suite.Getting an API KeyTo obtain a free Transpose API key, sign up on ourwebsite. Free tier keys have a rate limit of 1 request per second and 250,000 credits per month. If you need higher rate limits for your project or business, don't hesitate to reach out on our Discord or upgrade your tier directly in the webapp!Join ourDiscordto ask technical questions, share what you're building, and chat with others in the community.InstallationPython 3.8 or higher is recommendedTo install the python SDK, you can run the following command:python3 -m pip install -U transpose-dataDocumentationYou can find specific documentation on a per-product basis below.ProductDescriptionDocumentationBlock APIThe Block API provides endpoints for accessing low-level blockchain data at scale, including accounts, blocks, transactions, internal transactions, and logs.Block API DocsENS APIThe ENS API provides endpoints for looking up ENS names (both historical and primary), resolving ENS names and records, and monitoring ENS transfers and sales.ENS API DocsNFT APIThe NFT API provides endpoints for retrieving any collection and NFT in existence, as well as NFT images, operators, owners, transfers, approvals, and much more (fully supports both ERC-721 and ERC-1155 NFTs).NFT API DocsToken APIThe Token API provides endpoints for retrieving any token, token balance, transfer, and symbol in existence, including full support for native token transfers and balances (fully supports both ERC-20 and ERC-777 tokens).Token API DocsSQL APIThe SQL API provides direct SQL access to our entire ecosystem of indexed blockchain data. Paired with our robust indexing pipeline, SQL access gives unlimited flexibility in how you mix, aggregate, and query activity across the blockchain.SQL API DocsEndpoint APIThe Endpoint API provides customized REST endpoints that you can create, version, and use directly in your production applications.Endpoint API DocsSDK DocumentationYou can learn more about the Transpose SDK and how it works below.SDK Helpersstringify_listConverts a list of strings into a single string, separated by a delimiter.fromtranspose.src.util.formatimportstringify_liststringify_list(['a','b','c'],',')>>>'a,b,c'SDK ClassesThe Transpose SDK uses custom classes to represent API responses:Error ClassesSDK Error Class SpecificationsThe SDK uses the following error classes to represent API errors:TransposeBadRequestRepresents a 400 Bad Request error from the Transpose API.TransposeRateLimitRepresents a 429 Rate Limit error from the Transpose API.TransposeInvalidAPIKeyRepresents a 401 Unauthorized error from the Transpose API.TransposeInternalServerErrorRepresents a 500 Internal Server Error error from the Transpose API.TransposeResourceNotFoundRepresents a 404 Not Found error from the Transpose API.These errors will be raised when the SDK encounters an error from the Transpose API.Response Classes (DEPRECATED AS OF v3.1.0)Response Class SpecificationsThe SDK will always return a list of response objects from the Transpose API. For example, calling theens.records_by_dateendpoint will return a list ofENSRecordobjects.These response objects can be accessed in the following ways:ENSRecord[0].ens_namewill return the first record's ens_name.ENSRecord[i].ens_nameretrieves the ens_name from the i-th responseAll response objects can also be accessed as a dictionary by calling.to_dict()on them:ENSRecord[0].to_dict()will return the first record as a dictionary.ENSRecord[i].to_dict()retrieves the i-th record as a dictionary.SDK OptionsThe Transpose SDK can be configured to your liking, allowing you to change the default behavior of the SDK.Updating Chain IDUpdating SDK Working Chain IDIf you want to change the chain ID of your query, you can do so by setting thechain_idorchainproperties of theTransposeobject. For example, if you want to query the Ethereum mainnet, you can do so by running the following code:fromtransposeimportTransposeapi=Transpose(api_key="YOUR_API_KEY",chain_id=1)orfromtransposeimportTransposeapi=Transpose(api_key="YOUR_API_KEY",chain_id="ethereum")if you wish to change the chain ID of an existingTransposeobject, you can do so by running the following code:api.set_chain("ethereum")orapi.set_chain(1)Currently supported chainsChain IDChain Name1Ethereum137PolygonRaw JSON ResponsesOpt-in to raw JSON ResponsesIf you wish to receive responses in JSON format, you can set the `json` parameter to `True` when initializing the SDK. This will return all responses as JSON objects.Response classes are considered deprecated as of v3.1.0 and will be removed in v4.0.0. JSON responses will become standard in v4.0.0fromtranspose_sdkimportTransposeapi=Transpose(api_key="YOUR_API_KEY",json=True)PaginationPagination with the Transpose SDK.Transpose endpoints will return a maximum of 500 results in a single query. To return the next page, simply callapi.next(). Ifapi.next()returnsNone, then there are no more pages.Here is a standard pagination implementation:whileTrue:data=api.next()# sleep to avoid rate limitstime.sleep(1)# if there are no more pages, exit loopifdataisNone:break# otherwise, print length of dataelse:print(len(data))Bulk RequestsBulk requesting data with the Transpose SDKAlongside pagination, we also offer a convenience method for iterating over all pages. This method will handle pagination for you, and will return a list of all results.Usage:api.bulk_request(endpoint_response,requests_per_second,results_to_fetch)ParameterRequiredDescriptionTypeendpoint_responseYesThe called API function, which returns a list of data models.Listrequests_per_secondNoThe number of requests per second to makeintresults_to_fetchNoThe number of results to fetchintResponsesCodeTitleModel200SuccessData Model400Bad RequestError401UnauthorizedError403ForbiddenError404Not FoundError500Internal Server ErrorErrorHere is an example of how to usebulk_request:recent_blocks_since=api.bulk_request(api.block.blocks_by_date(added_after='2022-01-01 00:00:00',limit=500))print(len(recent_blocks_since))>>>500SDK ExtrasThe following methods are available as extras to the Transpose SDK.You can import extras to your project by using:fromtranspose.extrasimport<MODULE>Some extras will require additional dependencies to be installed. If you are missing dependencies, the SDK will throw aTransposeDependencyErrorwhen you try to import the extra. This error will tell you what dependencies are missing, and give you the exact command to install them:transpose.src.util.errors.TransposeDependencyError:MissingDependencies.Youcaninstallthesevia`pipinstallplotlykaleido`PlottingTranspose Plotting SpecificationsThe SDK natively includes a plotting library which implementsplotly. Using it, you can quickly create plots of data obtained through the Transpose API.For a plotting example, check out thedemofile, which will graph the past hour's gas prices in a bar chart.UsageYou'll first need to install the plotting dependencies using:pipinstallplotlykaleidoInstantiating a new plot is as simple as importing thePlotclass and instantiating it:fromtranspose.extrasimportPlotchart=Plot(title="Hourly Gas Prices on Ethereum")This will return an object on which you can call the following methods:Plot.plotly()Returns the current plot as a plotly object. From there, you can further customize the plot.Plot.show()Renders the current plot in the browser. This plot is interactive, and can be zoomed and panned.Plot.render(path, format)Inputs:path-> The path to render the plot to.format-> The format to render the plot as. Can be eitherpng,html,jpg, etc.Plot.add_data(data, type, shape, smoothing)Inputs:data-> The data to add to the plot. Takes the following format:{"x":[],// List of data"y":[],// List of data"y_axis":"Gas Price (Gwei)",// OPTIONAL: The name of the y-axis"x_axis":"Time",// OPTIONAL: The name of the x-axis}type-> OPTIONAL: The method used to render the data to the plot. Can be eitherlineorbar.shape-> OPTIONAL: The shape of the line. Can be eitherlinear,spline,vh,hv,vhv, orhvh.smoothing-> OPTIONAL: The number of points to smooth the data with.Forline, this will calculate a moving average of the data with a period ofsmoothing.Forbar, this will group and average the data oversmoothingpoints.Making a RequestTo get started and make your first request, make a newTransposeobject:fromtransposeimportTransposeapi=Transpose('transpose_api_key')From there, you can call endpoints from theapi.nft,api.ens,api.token, andapi.blocksubclasses.Debugging RequestsYou can view the raw HTTP requests the SDK is making by setting thedebugflag toTruewhen creating a newTransposeobject. For example:fromtransposeimportTransposeapi=Transpose('transpose_api_key',debug=True)Simple DemoTo show just how powerful our data is, let's get the last ENS domain that expired. All we need is one API call.fromtransposeimportTransposeapi=Transpose('transpose_api_key')# get the most recently expired ENS domainlast_expired=api.ens.records_by_date(type='expiration',order='desc',limit=1)This returns a list ofENS Records, which includes data which you wouldn't be able to easily get from the ENS protocol.[{"ens_name":"game-master-dit-gm.eth","ens_node":"9BFFC8C1EDE1E51E4BAE137FA37A81CC0379FC08123C4AA00A931D0D983956B7","contract_address":"0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85","token_id":75929000750162030430773866845127925090084516346841580577625168871716954805188,"meta_block_number":407909,"owner":"0x2aC92629c4E0E5e4868588f87DC4356606a590b6","resolver":"0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41","resolved_address":"0x2aC92629c4E0E5e4868588f87DC4356606a590b6","registration_timestamp":"2022-01-01T05:00:36Z","expiration_timestamp":"2049-12-31T23:58:12Z","grace_period_ends":"2050-03-31T23:58:12Z","premium_period_ends":"2050-04-21T23:58:12Z","in_grace_period":false,"in_premium_period":false,"is_expired":false,"last_refreshed":"2022-06-01T09:51:23Z"}]LinksSDK ExamplesTranspose DocumentationOfficial Discord Server