PEP 8 Coding Standards
Relevant source files
The following files were used as context for generating this wiki page:
Stolgo explicitly requires contributors to adhere to the PEP 8 Coding Style guidelines for all Python development within the project. This standard ensures that the codebase remains readable, consistent, and maintainable as a Price Action Trading Analysis Library.
The project emphasizes these standards particularly for major changes and pull requests, linking directly to the official Python PEP 8 documentation to guide developers in maintaining a professional code structure.
Sources: README.md:46-48, setup.py:41-47
Structural Implementation of PEP 8
The Stolgo library implements PEP 8 through specific architectural choices, including class-based organization, standardized naming conventions, and consistent documentation patterns. The codebase is organized into logical modules under the lib/stolgo directory, separating concerns such as data fetching, technical analysis, and exception handling.
Class and Method Naming
The project follows standard Python naming conventions:
- Classes: Use PascalCase (e.g.,
CandleStick,Breakout,RequestUrl). - Methods and Functions: Use snake_case (e.g.,
is_bullish_engulfing,get_data,is_consolidating). - Internal Methods: Prefixed with double underscores for pseudo-private members (e.g.,
__build_url,__get_hist_data).
Sources: lib/stolgo/candlestick.py:3-9, lib/stolgo/samco.py:34-45, lib/stolgo/breakout.py:8-12
Import Organization
Imports are grouped logically at the top of files, typically starting with standard library imports, followed by third-party packages (like pandas and requests), and ending with local project modules.
Sources: lib/stolgo/request.py:1-5, lib/stolgo/samco.py:1-8, lib/stolgo/trend.py:1-3
Documentation and Docstrings
Stolgo utilizes structured docstrings to explain function purposes, parameters, and return types. This is critical for a technical library where users need to understand the financial logic behind APIs.
Standard Docstring Format
The library uses a consistent format for documenting methods:
- Summary: A concise description of the function's action.
- Parameters: Detailed list with
:paramand:type. - Raises: Exception types documented with
:raises. - Returns: Return description with
:returnand:rtype.
def is_consolidating(self,dfs,periods=None,percentage=None):
"""Check if price in consolidating in range for given periods
:param dfs: input candles
:type dfs: pandas dataframe
:param periods: Number of candles, defaults to None
:type periods: integer, optional
:param percentage: range of consolidation in percentage, defaults to None
:type percentage: float, optional
:raises BadDataError: data error
:return: is_consolidating
:rtype: bool
"""
Sources: lib/stolgo/breakout.py:8-23, lib/stolgo/trend.py:9-23
Analysis Logic Flow
The following diagram illustrates how the standardized coding structure supports the flow of data from raw candles to technical signals within the Stolgo framework.
This diagram shows the relationship between data retrieval classes and analysis classes, highlighting the consistent method naming and data handling.
Sources: lib/stolgo/candlestick.py, lib/stolgo/samco.py, lib/stolgo/breakout.py, lib/stolgo/trend.py
Module Comparison Table
| Feature | Pattern | Example File |
|---|---|---|
| Exception Handling | Custom Exception Classes | lib/stolgo/exception.py |
| Data Resampling | Centralized Helper Functions | lib/stolgo/helper.py |
| HTTP Requests | Adapter Pattern with Retries | lib/stolgo/request.py |
| URL Management | Dedicated URL Registry Classes | lib/stolgo/samco.py |
Sources: lib/stolgo/exception.py:1-3, lib/stolgo/helper.py:85-88, lib/stolgo/request.py:12-23, lib/stolgo/samco.py:12-32
Summary of Coding Standards
Adherence to PEP 8 in Stolgo is not just a stylistic preference but a requirement for contribution. By maintaining consistent naming, rigorous docstrings, and a modular architecture, the project ensures that its price action trading tools remain accessible to the developer community. Contributors are expected to update tests alongside code changes to maintain the integrity of these standards.
Sources: README.md:46-51