### Install Dependencies with uv Source: https://github.com/tradeparadex/paradex-py/blob/main/CLAUDE.md Installs project dependencies using the uv package manager. This is the primary command for setting up the development environment. ```bash # Install dependencies using uv (fast Python package manager) make install ``` ```bash # Or directly with uv: uv sync ``` -------------------------------- ### Install pre-commit hooks Source: https://github.com/tradeparadex/paradex-py/blob/main/CONTRIBUTING.md Installs the pre-commit framework to automatically run linters and formatters before each commit. This helps maintain code quality and consistency. ```bash uv run pre-commit install ``` -------------------------------- ### Paradex Python SDK Development Commands Source: https://github.com/tradeparadex/paradex-py/blob/main/README.md A collection of make commands for managing the development lifecycle of the Paradex Python SDK, including installation, testing, building, and documentation generation. ```bash make install make check make test make build make clean-build make publish make build-and-publish make docs-test make docs make help ``` -------------------------------- ### Install dependencies with uv Source: https://github.com/tradeparadex/paradex-py/blob/main/CONTRIBUTING.md Installs and synchronizes project dependencies using the `uv` package manager. This command ensures the local environment matches the project's requirements. ```bash uv sync ``` -------------------------------- ### Install uv Package Manager (Bash) Source: https://github.com/tradeparadex/paradex-py/blob/main/README.md Installs the `uv` package manager using a script from `astral.sh`. `uv` is a fast and modern Python package manager used for dependency management and building. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Run tests across multiple Python versions with tox Source: https://github.com/tradeparadex/paradex-py/blob/main/CONTRIBUTING.md Uses `tox` to run tests across different Python versions, simulating the CI/CD environment. This requires multiple Python versions to be installed locally. ```bash tox ``` -------------------------------- ### Initialize Paradex SDK and Fetch Data (Python) Source: https://github.com/tradeparadex/paradex-py/blob/main/README.md Demonstrates initializing the Paradex SDK with testnet environment, retrieving L2 account details, fetching system configuration, and subscribing to market data via WebSocket. ```python from paradex_py import Paradex from paradex_py.environment import Environment paradex = Paradex(env=Environment.TESTNET, l1_address="0x...", l1_private_key="0x...") print(hex(paradex.account.l2_address)) # 0x... print(hex(paradex.account.l2_public_key)) # 0x... print(hex(paradex.account.l2_private_key)) # 0x... paradex.api_client.fetch_system_config() # { ..., "paraclear_decimals": 8, ... } async def on_message(ws_channel, message): print(ws_channel, message) await paradex.ws_client.connect() await paradex.ws_client.subscribe(ParadexWebsocketChannel.MARKETS_SUMMARY, callback=on_message) ``` -------------------------------- ### Build and Serve Documentation Source: https://github.com/tradeparadex/paradex-py/blob/main/CLAUDE.md Builds the project's documentation locally and serves it for viewing. Also includes an option to just test the documentation build process. ```bash # Build and serve documentation locally make docs ``` ```bash # Or test documentation build make docs-test ``` -------------------------------- ### Basic Workflow with uv for Python Development (Bash) Source: https://github.com/tradeparadex/paradex-py/blob/main/README.md Provides essential `uv` commands for managing Python project dependencies, running tests, and building the project without relying on `make`. ```bash uv sync uv run pytest uv build ``` -------------------------------- ### Clone paradex-py repository Source: https://github.com/tradeparadex/paradex-py/blob/main/CONTRIBUTING.md Clones the paradex-py repository locally using Git. This is the first step after forking the project on GitHub. ```bash cd git clone git@github.com:YOUR_NAME/paradex-py.git ``` -------------------------------- ### Run unit tests Source: https://github.com/tradeparadex/paradex-py/blob/main/CONTRIBUTING.md Executes all unit tests for the project using the `make test` command. This ensures that new changes do not break existing functionality. ```bash make test ``` -------------------------------- ### Build Project Package Source: https://github.com/tradeparadex/paradex-py/blob/main/CLAUDE.md Creates a distributable package of the Paradex-Py project. This is typically used before publishing or deploying. ```bash # Build the package make build ``` -------------------------------- ### Run code formatting and linting checks Source: https://github.com/tradeparadex/paradex-py/blob/main/CONTRIBUTING.md Executes the `make check` command to verify that the code adheres to project formatting and linting standards. This is a pre-commit check. ```bash make check ``` -------------------------------- ### Run Pre-commit Hooks Source: https://github.com/tradeparadex/paradex-py/blob/main/CLAUDE.md Manually triggers the pre-commit framework to run all configured hooks. Useful for ensuring local changes meet commit quality gates. ```bash # Run pre-commit hooks manually uv run pre-commit run -a ``` -------------------------------- ### Generate API models Source: https://github.com/tradeparadex/paradex-py/blob/main/CONTRIBUTING.md Generates Pydantic v2 API models from the Paradex OpenAPI specification. It can fetch the spec from a URL or use a local file, with options for a custom output directory. ```bash # Fetch from API (default) uv run scripts/generate_models_simple.py # Use local spec file uv run scripts/generate_models_simple.py --spec-file path/to/spec.json # Use local spec file with custom output directory uv run scripts/generate_models_simple.py --spec-file path/to/spec.json --output-dir custom/output ``` -------------------------------- ### Run Tests and Coverage Source: https://github.com/tradeparadex/paradex-py/blob/main/CLAUDE.md Executes the test suite and measures code coverage. Allows running all tests or a specific test function for focused debugging. ```bash # Run tests with coverage make test ``` ```bash # Or run a single test: uv run pytest tests/path/to/test_file.py::test_function_name ``` -------------------------------- ### Commit and push changes Source: https://github.com/tradeparadex/paradex-py/blob/main/CONTRIBUTING.md Commits staged changes with a descriptive message and pushes the current branch to the remote GitHub repository. ```bash git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### Create a new development branch Source: https://github.com/tradeparadex/paradex-py/blob/main/CONTRIBUTING.md Creates a new Git branch for local development of a bug fix or new feature. This isolates changes and facilitates a clean pull request. ```bash git checkout -b name-of-your-bugfix-or-feature ``` -------------------------------- ### Generate Pydantic Models from OpenAPI Spec (Python) Source: https://github.com/tradeparadex/paradex-py/blob/main/scripts/README.md This script fetches the Paradex API OpenAPI specification or uses a local file to generate Pydantic v2 models. It can optionally convert Swagger 2.0 to OpenAPI 3.0 and allows specifying an output directory. Dependencies include `datamodel-code-generator`, `httpx`, and optionally `swagger2openapi`. ```python import argparse import json import os import shutil import tempfile import httpx from datamodel_code_generator import InputFileType, generate # Optional import for swagger conversion try: from swagger2openapi import convert except ImportError: convert = None def fetch_spec(url): """Fetches the OpenAPI specification from a URL.""" try: response = httpx.get(url) response.raise_for_status() # Raise an exception for bad status codes return response.json() except httpx.RequestError as exc: print(f"An error occurred while requesting {exc.request.url!r}. {exc}") return None except json.JSONDecodeError: print("Error decoding JSON response.") return None def generate_models(spec_file=None, output_dir='paradex_py/api/generated'): """Generates Pydantic models from an OpenAPI specification. Args: spec_file (str, optional): Path to a local JSON spec file. If None, fetches from the default API URL. output_dir (str, optional): Directory to save generated models. Defaults to 'paradex_py/api/generated'. """ api_url = "https://api.prod.paradex.trade/swagger/doc.json" input_spec_data = None if spec_file: try: with open(spec_file, 'r') as f: input_spec_data = json.load(f) print(f"Using local spec file: {spec_file}") except FileNotFoundError: print(f"Error: Spec file not found at {spec_file}") return except json.JSONDecodeError: print(f"Error: Could not decode JSON from {spec_file}") return else: print(f"Fetching spec from API: {api_url}") input_spec_data = fetch_spec(api_url) if input_spec_data is None: print("Failed to fetch spec from API. Exiting.") return # Convert Swagger 2.0 to OpenAPI 3.0 if necessary and converter is available if 'swagger' in input_spec_data and input_spec_data['swagger'] == '2.0': if convert: print("Converting Swagger 2.0 to OpenAPI 3.0...") try: # Use a temporary file for conversion output with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as tmp_spec: # The convert function writes to stdout by default if output is not specified # We need to capture this output or redirect it. # A simpler approach for this script is to pass a file-like object. # However, the convert function might not directly support file-like objects for output. # Let's assume we write to a temp file and then read back. # Create a temporary file for the input spec data to pass to convert with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as tmp_input_spec_file: json.dump(input_spec_data, tmp_input_spec_file) tmp_input_spec_file_path = tmp_input_spec_file.name # Run the conversion, capturing stdout import subprocess result = subprocess.run(['swagger2openapi', tmp_input_spec_file_path, '--output', tmp_spec.name], capture_output=True, text=True) if result.returncode == 0: with open(tmp_spec.name, 'r') as f: input_spec_data = json.load(f) print("Conversion successful.") else: print(f"Swagger conversion failed: {result.stderr}") # Optionally, proceed with original data or exit # For now, we will proceed with the original data if conversion fails except Exception as e: print(f"An unexpected error occurred during conversion: {e}") # Proceed with original data if conversion fails finally: # Clean up temporary files if 'tmp_input_spec_file_path' in locals() and os.path.exists(tmp_input_spec_file_path): os.unlink(tmp_input_spec_file_path) if tmp_spec.name and os.path.exists(tmp_spec.name): os.unlink(tmp_spec.name) else: print("Warning: `swagger2openapi` not installed. Cannot convert Swagger 2.0 spec.") # Ensure output directory exists os.makedirs(output_dir, exist_ok=True) # Generate Pydantic models print(f"Generating Pydantic models into: {output_dir}") try: generate( input_=json.dumps(input_spec_data), # Pass JSON string directly input_file_type=InputFileType.OpenAPI, # Specify input type output=output_dir, extra_template_data={"base_class": "BaseModel"}, # Example: Use BaseModel as base class custom_file_header="# -*- coding: utf-8 -*-\n# Generated by generate_models_simple.py\n\n", # Use specific template for desired output structure if needed # For this example, let's assume default templates are sufficient or customized elsewhere # If specific files (model.py, requests.py, responses.py) are desired, custom templates might be required ) print("Model generation complete.") # The datamodel-code-generator typically creates a single file or structured output based on input. # To match the description's expected files (model.py, requests.py, responses.py), # custom templates or post-processing might be needed. # For this example, we'll acknowledge the output directory. print(f"Generated models are located in: {output_dir}") except Exception as e: print(f"Error during model generation: {e}") if __name__ == "__main__": parser = argparse.ArgumentParser(description='Generate Pydantic models from Paradex API specification.') parser.add_argument('--spec-file', type=str, help='Path to local JSON spec file (fetches from API if not provided)') parser.add_argument('--output-dir', type=str, default='paradex_py/api/generated', help='Output directory for generated models') args = parser.parse_args() generate_models(args.spec_file, args.output_dir) ``` -------------------------------- ### Run Code Quality Checks Source: https://github.com/tradeparadex/paradex-py/blob/main/CLAUDE.md Executes all automated code quality checks, including linting, type checking, and dependency validation. Ensures code adheres to project standards. ```bash # Run all code quality checks (linting, type checking, dependency checks) make check ``` -------------------------------- ### Perform Type Checking Source: https://github.com/tradeparadex/paradex-py/blob/main/CLAUDE.md Runs MyPy for static type checking on the project's Python code. Helps catch type-related errors before runtime. ```bash # Type checking uv run mypy --check-untyped-defs paradex_py ``` -------------------------------- ### Regenerate API Models Source: https://github.com/tradeparadex/paradex-py/blob/main/CLAUDE.md Regenerates Pydantic models used by the API clients from the OpenAPI specification. This script should be run if the spec changes. ```bash uv run python scripts/generate_models_simple.py ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.