### Copy Environment Example Source: https://github.com/polymarket/py-sdk/blob/main/CONTRIBUTING.md Copy the example environment file to start configuring local settings. Fill in only the values needed for the tests you intend to run. ```bash cp .env.example .env ``` -------------------------------- ### Install Polymarket Client (uv) Source: https://github.com/polymarket/py-sdk/blob/main/README.md Installs the Polymarket client package with prerelease versions allowed using uv. ```bash uv add --prerelease allow polymarket-client ``` -------------------------------- ### Run Development Setup Source: https://github.com/polymarket/py-sdk/blob/main/CONTRIBUTING.md Execute this command to synchronize development dependencies and set up the environment. ```bash make sync ``` -------------------------------- ### Install Polymarket Client (pip) Source: https://github.com/polymarket/py-sdk/blob/main/README.md Installs the Polymarket client package, including pre-release versions, using pip. ```bash pip install --pre polymarket-client ``` -------------------------------- ### Conventional Commit Examples Source: https://github.com/polymarket/py-sdk/blob/main/CONTRIBUTING.md Examples illustrating the correct format for Conventional Commits, including feature additions and bug fixes with scopes. ```text feat: add market lookup fix(auth): refresh expired credentials ``` -------------------------------- ### Instantiate Synchronous Client Source: https://github.com/polymarket/py-sdk/blob/main/docs/sdk-direction.md Use the default synchronous client for straightforward scripting and data retrieval. No special setup is required beyond importing the client class. ```python from polymarket import PublicClient client = PublicClient() market = client.get_market(id="540816") ``` -------------------------------- ### Integration Test Requiring Environment Variables Source: https://github.com/polymarket/py-sdk/blob/main/README.md An example integration test that uses the require_env fixture to ensure necessary environment variables (like API keys) are available. ```python import pytest @pytest.mark.integration def test_authenticated_flow(require_env): private_key = require_env("POLYMARKET_PRIVATE_KEY") builder_api_key = require_env("POLYMARKET_BUILDER_API_KEY") assert private_key assert builder_api_key ``` -------------------------------- ### Metered Integration Test Source: https://github.com/polymarket/py-sdk/blob/main/README.md An example integration test marked as 'metered', which requires a specific environment variable to be set to run. These tests may mutate live state. ```python import pytest @pytest.mark.integration @pytest.mark.metered def test_order_lifecycle(require_env): private_key = require_env("POLYMARKET_PRIVATE_KEY") assert private_key ``` -------------------------------- ### Synchronous Client Usage Source: https://github.com/polymarket/py-sdk/blob/main/README.md Demonstrates how to initialize and use the synchronous Polymarket public client to fetch market data. ```python from polymarket import Market, PublicClient with PublicClient() as client: market: Market = client.get_market(url="https://polymarket.com/event/example-market") ``` -------------------------------- ### Run Integration Tests Source: https://github.com/polymarket/py-sdk/blob/main/CONTRIBUTING.md Execute integration tests locally after setting up the `.env` file. Ensure you use disposable test credentials and never commit `.env` files. ```bash make test-integration ``` -------------------------------- ### Run Unit Tests Source: https://github.com/polymarket/py-sdk/blob/main/README.md Executes the unit tests for the Polymarket Python SDK by default using the make test command. ```bash make test ``` -------------------------------- ### Asynchronous Client Usage Source: https://github.com/polymarket/py-sdk/blob/main/README.md Shows how to initialize and use the asynchronous Polymarket public client within an asyncio event loop to fetch market data. ```python import asyncio from polymarket import AsyncPublicClient, Market async def main() -> None: async with AsyncPublicClient() as client: market: Market = await client.get_market( url="https://polymarket.com/event/example-market" ) asyncio.run(main()) ``` -------------------------------- ### Run Code Checks Source: https://github.com/polymarket/py-sdk/blob/main/CONTRIBUTING.md Execute this command to run all configured code quality and style checks. ```bash make check ``` -------------------------------- ### Instantiate Asynchronous Client Source: https://github.com/polymarket/py-sdk/blob/main/docs/sdk-direction.md Employ the `AsyncPublicClient` for asynchronous operations, maintaining the same API structure as the synchronous client. This is suitable for I/O-bound tasks where non-blocking operations are beneficial. ```python from polymarket import AsyncPublicClient client = AsyncPublicClient() market = await client.get_market(id="540816") ``` -------------------------------- ### Build Package Artifacts Source: https://github.com/polymarket/py-sdk/blob/main/README.md Builds the distributable package artifacts for the Polymarket Python SDK using the make build command. ```bash make build ``` -------------------------------- ### Synchronous Client as Context Manager Source: https://github.com/polymarket/py-sdk/blob/main/docs/sdk-direction.md Manage resources deterministically by using the synchronous client within a `with` statement. This ensures the client's transport resources are properly cleaned up upon exiting the block. ```python from polymarket import PublicClient with PublicClient() as client: market = client.get_market(id="540816") ``` -------------------------------- ### Asynchronous Client as Context Manager Source: https://github.com/polymarket/py-sdk/blob/main/docs/sdk-direction.md Utilize the asynchronous client with `async with` for automatic resource management in asynchronous contexts. This pattern ensures that asynchronous transport resources are released correctly. ```python from polymarket import AsyncPublicClient async with AsyncPublicClient() as client: market = await client.get_market(id="540816") ``` -------------------------------- ### Load Private Key for Authenticated Flow Source: https://github.com/polymarket/py-sdk/blob/main/tests/integration/README.md Use the `require_env` fixture to load sensitive environment variables like POLYMARKET_PRIVATE_KEY for authenticated API calls. This fixture ensures tests fail cleanly if secrets are not available. ```python def test_authenticated_flow(require_env): private_key = require_env("POLYMARKET_PRIVATE_KEY") ``` -------------------------------- ### Run Unit Tests in Watch Mode Source: https://github.com/polymarket/py-sdk/blob/main/README.md Runs unit tests and automatically re-runs them when Python files change, using the make test-watch command. ```bash make test-watch ``` -------------------------------- ### Importing Domain Types Source: https://github.com/polymarket/py-sdk/blob/main/docs/sdk-direction.md Import generic domain primitives like `EvmAddress`, `HexString`, and `TransactionHash` from the top-level `polymarket` package for use in type hinting and validation. ```python from polymarket import EvmAddress, HexString, TransactionHash ``` -------------------------------- ### Run Metered Integration Tests Source: https://github.com/polymarket/py-sdk/blob/main/CONTRIBUTING.md Run integration tests that are marked as metered. This requires setting the `POLYMARKET_RUN_METERED_TESTS` environment variable. ```bash POLYMARKET_RUN_METERED_TESTS=1 make test-integration ``` -------------------------------- ### Mark Metered Integration Test Source: https://github.com/polymarket/py-sdk/blob/main/CONTRIBUTING.md Apply both `@pytest.mark.integration` and `@pytest.mark.metered` decorators to tests that mutate live state or spend funds. These tests are skipped by default and require `POLYMARKET_RUN_METERED_TESTS=1` to run. ```python import pytest @pytest.mark.integration @pytest.mark.metered def test_order_lifecycle(require_env): private_key = require_env("POLYMARKET_PRIVATE_KEY") ``` -------------------------------- ### Importing Model-Specific Identifiers Source: https://github.com/polymarket/py-sdk/blob/main/docs/sdk-direction.md Import model-specific identifiers such as `ConditionId`, `EventId`, `MarketId`, `OrderId`, and `TokenId` from the `polymarket` package. Note that `MarketId` is also re-exported from `polymarket.models` for convenience. ```python from polymarket import ConditionId, EventId, MarketId, OrderId, TokenId from polymarket.models import MarketId ``` -------------------------------- ### Mark Integration Test Source: https://github.com/polymarket/py-sdk/blob/main/CONTRIBUTING.md Use this decorator to mark tests that require integration with external services. The `require_env` fixture ensures necessary environment variables are present, skipping the test if they are missing. ```python import pytest @pytest.mark.integration def test_authenticated_flow(require_env): private_key = require_env("POLYMARKET_PRIVATE_KEY") ``` -------------------------------- ### Conventional Commit Format Source: https://github.com/polymarket/py-sdk/blob/main/CONTRIBUTING.md Commit subjects and PR titles must adhere to the Conventional Commits format: `(optional-scope): `. This format is used for automated release management. ```text (optional-scope): ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.