How ivarurdalen/coinalyze works
Project Type and Purpose
• This is an open-source Python client library (“coinalyze”) that wraps the coinalyze.net REST API.
• Its goal is to provide Pythonic functions for each API endpoint, enforce rate limits, handle retries, and optionally convert JSON responses into pandas DataFrames.
File Structure Analysis
• Top-level: configuration (.env.template, .github, pyproject.toml), examples, scripts, tests.
• src/coinalyze/: the library package
• client.py: core CoinalyzeClient, HTTP logic, rate limiting, retries
• constants.py, enums.py, types.py: API constants, enums (e.g. endpoints, intervals), typing definitions
• util/: helpers for request building and pandas conversion
• examples/: sample CLI and Jupyter notebook showing typical usage
• tests/: pytest suite validating client methods and utilities
README Insights
• Uses httpx for HTTP calls, pyrate-limiter for 40 calls/min, httpx-retries for retry behavior
• Provides response_to_df convenience for DataFrame output
• Environment variable COINALYZE_API_KEY for authentication
a. Main Components
1. User Application (e.g. CLI script, Jupyter notebook, downstream code)
2. coinalyze Library
– CoinalyzeClient
– Rate Limiter (pyrate-limiter)
– HTTPX Client + Retry Layer (httpx-retries)
– Utilities (request builders, JSON→DataFrame)
– Constants/Enums/Types
3. External Service: coinalyze.net REST API
4. Optional: pandas for DataFrame conversion
b. Relationships & Data Flows
1. The User App imports CoinalyzeClient and configures it with API key
2. Client constructs HTTP requests, passing through Rate Limiter and Retry layers
3. HTTPX executes the request against the coinalyze REST endpoint
4. JSON response returns to Client → parsed/typed → optionally fed to pandas util
5. Final Python objects or DataFrame returned to User App
c. Architectural Patterns
– Wrapper/Facade pattern: CoinalyzeClient hides HTTP intricacies
– Decorator or middleware for rate limiting and retry logic on HTTP calls
– Separation of concerns: constants/enums/types vs. core client vs. utils
d. Key Technologies & Libraries
– httpx (HTTP client)
– pyrate-limiter (rate limiting)
– httpx-retries (retry middleware)
– pandas (DataFrame conversion)
– pytest (testing)