oe-python-template-example 0.2.5__tar.gz → 0.2.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.copier-answers.yml +1 -1
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.github/workflows/codeql.yml +1 -1
- oe_python_template_example-0.2.6/CODE_STYLE.md +284 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/CONTRIBUTING.md +11 -12
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/PKG-INFO +120 -59
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/README.md +119 -58
- oe_python_template_example-0.2.6/SECURITY.md +59 -0
- oe_python_template_example-0.2.6/VERSION +1 -0
- oe_python_template_example-0.2.6/docs/partials/README_main.md +313 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/conf.py +1 -1
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/pyproject.toml +2 -2
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/sonar-project.properties +1 -1
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/uv.lock +1 -1
- oe_python_template_example-0.2.5/CODE_STYLE.md +0 -284
- oe_python_template_example-0.2.5/SECURITY.md +0 -60
- oe_python_template_example-0.2.5/VERSION +0 -1
- oe_python_template_example-0.2.5/docs/partials/README_main.md +0 -252
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.act-env-public +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.devcontainer/Dockerfile +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.devcontainer/devcontainer.json +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.devcontainer/onCreateCommand +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.devcontainer/postAttachCommand +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.devcontainer/postCreateCommand +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.env.example +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.github/copilot-instructions.md +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.github/dependabot.yml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.github/workflows/docker-image-build-publish.yml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.github/workflows/package-build-publish-release.yml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.github/workflows/test-and-report.yml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.gitignore +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.pre-commit-config.yaml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.python-version +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.readthedocs.yml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.secrets.baseline +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.vscode/extensions.json +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.vscode/settings.json +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/CHANGELOG.md +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/CODEOWNERS +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/Dockerfile +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/LICENSE +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/RELEASE_NOTES.md +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/SERVICE_CONNECTIONS.md +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/bin/git-cliff +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/codecov.yml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/compose.yaml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/Makefile +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/make.bat +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/partials/README_footer.md +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/partials/README_header.md +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/_static/.keep +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/_static/openapi.json +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/_static/openapi.yaml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/_static/openapi_v1.json +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/_static/openapi_v1.yaml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/_static/openapi_v2.json +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/_static/openapi_v2.yaml +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/api_v1.rst +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/api_v2.rst +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/code-style.rst +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/contributing.rst +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/index.rst +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/main.rst +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/reference.rst +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/release-notes.rst +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/docs/source/security.rst +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/examples/__init__.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/examples/notebook.ipynb +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/examples/notebook.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/examples/script.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/examples/streamlit.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/CHANGELOG.md +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/LICENSE-APACHE +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/LICENSE-MIT +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/README.md +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/completions/_git-cliff +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/completions/_git-cliff.ps1 +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/completions/git-cliff.bash +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/completions/git-cliff.elv +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/completions/git-cliff.fish +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/git-cliff-completions +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/git-cliff-mangen +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0/man/git-cliff.1 +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/git-cliff-2.7.0-x86_64-unknown-linux-gnu.tar.gz +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/github-action-run +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/logo.png +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/n +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/noxfile.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/renovate.json +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/reports/.keep +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/src/oe_python_template_example/__init__.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/src/oe_python_template_example/api.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/src/oe_python_template_example/cli.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/src/oe_python_template_example/constants.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/src/oe_python_template_example/service.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/tests/__init__.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/tests/api_test.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/tests/cli_test.py +0 -0
- {oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/tests/fixtures/.keep +0 -0
{oe_python_template_example-0.2.5 → oe_python_template_example-0.2.6}/.github/workflows/codeql.yml
RENAMED
@@ -59,7 +59,7 @@ jobs:
|
|
59
59
|
- name: Checkout repository
|
60
60
|
uses: actions/checkout@v4
|
61
61
|
|
62
|
-
|
62
|
+
# Add any setup steps before running the `github/codeql-action/init` action.
|
63
63
|
# This includes steps like installing compilers or runtimes (`actions/setup-node`
|
64
64
|
# or others). This is typically only required for manual builds.
|
65
65
|
# - name: Setup runtime (example)
|
@@ -0,0 +1,284 @@
|
|
1
|
+
# Code Style
|
2
|
+
|
3
|
+
Author: Helmut Hoffer von Ankershoffen (@helmut-hoffer-von-ankershoffen ) - Status: Draft - Created: 2025-03-16 - Updated: 2025-03-16
|
4
|
+
|
5
|
+
This document describes the code style used in
|
6
|
+
[oe-python-template](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template)
|
7
|
+
and derivatives. It defines strict requirements to be followed by all
|
8
|
+
contributors - humans and agents - to ensure consistency and readability across
|
9
|
+
the codebase.
|
10
|
+
|
11
|
+
## Code
|
12
|
+
|
13
|
+
We favor readability and maintainability over cleverness and brevity.
|
14
|
+
|
15
|
+
1. We always write code that is easy to read, understand, maintain, test,
|
16
|
+
document, deploy, use, integrate, and extend.
|
17
|
+
2. We always write code that is efficient and performant, but only if it does not
|
18
|
+
sacrifice readability, maintainability, and testability.
|
19
|
+
3. We always write code that is secure and does not introduce vulnerabilities.
|
20
|
+
4. We always write code that is portable and does not introduce platform-specific
|
21
|
+
dependencies.
|
22
|
+
5. We always write code that is compatible with the Python version indicated in
|
23
|
+
the .python-version file in the root of this repository.
|
24
|
+
|
25
|
+
## Naming
|
26
|
+
|
27
|
+
We believe that good names are essential for code readability and
|
28
|
+
maintainability. A good name is one that is descriptive, unambiguous, and
|
29
|
+
meaningful. It should convey the purpose and intent of the code it represents.
|
30
|
+
|
31
|
+
1. We take extra care to find proper names for all identifiers, including
|
32
|
+
variables, functions, classes, types, tests, modules, and packages. We prefer
|
33
|
+
descriptive names that clearly indicate the purpose and functionality of the
|
34
|
+
code.
|
35
|
+
2. We avoid using abbreviations, acronyms, and jargon unless they are widely
|
36
|
+
understood and accepted in the context of the code. We prefer full words and
|
37
|
+
phrases that are easy to understand.
|
38
|
+
3. We avoid using single-letter names, except for loop variables and iterators.
|
39
|
+
4. We avoid using generic names like `data`, `info`, `temp`, `foo`, `bar`, etc.
|
40
|
+
These names do not convey any meaning and make the code harder to read and
|
41
|
+
understand.
|
42
|
+
5. We avoid using names that are too long or too short. A good name should be
|
43
|
+
concise but descriptive. It should be long enough to convey the purpose and
|
44
|
+
intent of the code, but not so long that it becomes cumbersome to read and
|
45
|
+
write.
|
46
|
+
6. We avoid using names that are too similar or too different. A good name should
|
47
|
+
be unique and distinct. It should not be confused with other names in the
|
48
|
+
code. It should not be so different that it becomes hard to remember and
|
49
|
+
recognize.
|
50
|
+
|
51
|
+
## Formatting
|
52
|
+
|
53
|
+
We use [ruff](https://github.com/astral-sh/ruff) to format Python code
|
54
|
+
|
55
|
+
1. The ruff formatter adheres to the
|
56
|
+
[Black](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html)
|
57
|
+
code style which is [PEP 8](https://www.python.org/dev/peps/pep-0008/)
|
58
|
+
compliant.
|
59
|
+
2. The ruff formatter is configured to use a max line length of 120.
|
60
|
+
3. The ruff formatter is called by the lint session of nox.
|
61
|
+
|
62
|
+
Beyond PEP 8 we adhere to the following naming conventions: We use the following
|
63
|
+
conventions for Python code:
|
64
|
+
|
65
|
+
1. Class names: `PascalCase` - descriptive nouns that clearly indicate purpose.
|
66
|
+
2. Function/method names: `snake_case` - verb phrases that describe actions.
|
67
|
+
3. Variables/attributes: `snake_case` - descriptive nouns/noun phrases.
|
68
|
+
4. Constants: `UPPER_SNAKE_CASE`.
|
69
|
+
5. Private members: Prefix with single underscore `_private_attribute`.
|
70
|
+
6. "True" private members: Prefix with double underscore `__truly_private`.
|
71
|
+
7. Type variables: `CamelCase` with short, descriptive names (e.g., `T`, `KT`,
|
72
|
+
`VT`).
|
73
|
+
8. Boolean variables/functions: Prefix with `is_`, `has_`, `should_`, etc.
|
74
|
+
9. Interface classes: Suffix with `Interface` or `Protocol`.
|
75
|
+
|
76
|
+
## Linting and type checking
|
77
|
+
|
78
|
+
We use [ruff](https://github.com/astral-sh/ruff) to lint Python code
|
79
|
+
|
80
|
+
1. All linting rules are enabled except those explicitly disabled in
|
81
|
+
pyproject.toml
|
82
|
+
2. The ruff linter is called by the lint session of nox.
|
83
|
+
|
84
|
+
We use [mypy](https://mypy.readthedocs.io/) for static type checking of Python
|
85
|
+
code.
|
86
|
+
|
87
|
+
1. mypy is configured to use the `strict` mode in pyproject.toml
|
88
|
+
2. mypy is called by the lint session of nox.
|
89
|
+
|
90
|
+
## Documentation
|
91
|
+
|
92
|
+
We use docstrings to document the purpose of modules, classes, types, functions,
|
93
|
+
its parameters and returns
|
94
|
+
|
95
|
+
1. We use Google style docstrings with typed Args and Returns.
|
96
|
+
2. We comment complex code and algorithms to explain their purpose and
|
97
|
+
functionality.
|
98
|
+
3. We leave references with deep links in code to external documentation,
|
99
|
+
standards, and specifications.
|
100
|
+
|
101
|
+
We provide an auto-generated OpenAPI specification and reference documentation.
|
102
|
+
|
103
|
+
We generate the final documentation using Sphinx and publish it to readthedocs.
|
104
|
+
|
105
|
+
1. Generation of documentation is called by the docs session of nox
|
106
|
+
|
107
|
+
## Testing
|
108
|
+
|
109
|
+
We use [pytest](https://docs.pytest.org/en/stable/) for testing Python code.
|
110
|
+
|
111
|
+
1. Tests are defined in the `tests/` directory
|
112
|
+
2. We use pytest fixtures to set up test data and state
|
113
|
+
3. We leverage several pytest plugins:
|
114
|
+
1. `pytest-asyncio` for testing async code
|
115
|
+
2. `pytest-cov` for coverage reporting
|
116
|
+
3. `pytest-docker` for integration tests with containers
|
117
|
+
4. `pytest-env` for environment variable management
|
118
|
+
5. `pytest-regressions` for regression testing
|
119
|
+
6. `pytest-xdist` for parallel test execution
|
120
|
+
4. Test execution is automated through the nox test session which runs across the
|
121
|
+
Python versions indicated in the `pyproject.toml`.
|
122
|
+
|
123
|
+
Our test coverage is measured using `pytest-cov` and reported in the CI
|
124
|
+
pipeline.
|
125
|
+
|
126
|
+
1. We aim for 100% unit coverage on all code paths, including error handling and
|
127
|
+
edge cases.
|
128
|
+
2. We fail the CI if unit test coverage drops below 85%.
|
129
|
+
|
130
|
+
Apart from unit tests we provide integration tests and end-to-end tests:
|
131
|
+
|
132
|
+
1. We smoke test as part of the CI/CD pipeline.
|
133
|
+
2. We facilitate exploratory testing to ensure comprehensive coverage.
|
134
|
+
3. We use `pytest-docker` for integration tests with containers.
|
135
|
+
|
136
|
+
## Error Handling
|
137
|
+
|
138
|
+
We use structured, explicit error handling that enables effective debugging and
|
139
|
+
monitoring:
|
140
|
+
|
141
|
+
1. Use specific exception classes instead of generic ones.
|
142
|
+
2. Include contextual information in exception messages.
|
143
|
+
3. Log exceptions with appropriate severity levels and context.
|
144
|
+
4. Gracefully degrade functionality when possible rather than failing completely.
|
145
|
+
5. Use type hints to catch type errors at compile time rather than runtime.
|
146
|
+
6. Design errors to be actionable for both users and developers.
|
147
|
+
|
148
|
+
## Logging
|
149
|
+
|
150
|
+
We log information to help with debugging and monitoring:
|
151
|
+
|
152
|
+
1. Use structured logging with consistent fields across all log entries.
|
153
|
+
2. Include correlation IDs for tracking requests across components.
|
154
|
+
3. Log at appropriate levels (DEBUG, INFO, WARNING, ERROR, CRITICAL).
|
155
|
+
4. Be mindful of PII and sensitive data in logs, using obfuscation where needed.
|
156
|
+
5. Consider log volume and performance impact in production environments.
|
157
|
+
|
158
|
+
## Performance Considerations
|
159
|
+
|
160
|
+
We consider performance from the early design stage, not as an afterthought:
|
161
|
+
|
162
|
+
1. Consider algorithmic complexity (Big O notation) for all operations.
|
163
|
+
2. Prefer lazy evaluation when dealing with large datasets.
|
164
|
+
3. Use appropriate data structures for specific access patterns.
|
165
|
+
4. Be mindful of memory usage, especially for long-running processes.
|
166
|
+
5. Consider profiling for critical paths and potential bottlenecks.
|
167
|
+
6. Document performance characteristics and assumptions.
|
168
|
+
7. Write benchmarks for performance-critical code.
|
169
|
+
8. Design for horizontal scaling from the beginning.
|
170
|
+
9. Use asynchronous operations appropriately for I/O-bound tasks.
|
171
|
+
10. Consider caching strategies when appropriate.
|
172
|
+
|
173
|
+
## API Design
|
174
|
+
|
175
|
+
For both internal and external APIs we follow the principle of least surprise.
|
176
|
+
|
177
|
+
1. We maintain backward compatibility whenever possible. If not possible we add a
|
178
|
+
new major version of the API.
|
179
|
+
2. Implement proper versioning for breaking changes.
|
180
|
+
3. Document error conditions, return values, and side effects.
|
181
|
+
4. Design for testability and mockability.
|
182
|
+
5. Provide sensible defaults while allowing for configuration.
|
183
|
+
6. Follow RESTful principles for HTTP APIs.
|
184
|
+
7. Use consistent parameter ordering and naming.
|
185
|
+
8. Implement proper validation with helpful error messages.
|
186
|
+
9. Consider rate limiting and circuit breaking for external services.
|
187
|
+
|
188
|
+
## Security
|
189
|
+
|
190
|
+
We prioritize security at every stage of development to prevent vulnerabilities
|
191
|
+
and protect our users.
|
192
|
+
|
193
|
+
1. Follow the principle of least privilege for all operations and access
|
194
|
+
controls.
|
195
|
+
2. Never store secrets (API keys, passwords, tokens) in code repositories.
|
196
|
+
1. Use environment variables or dedicated secret management services.
|
197
|
+
2. Code is checked via `detect-secrets` pre-commit hook to prevent accidental
|
198
|
+
commits of secrets.
|
199
|
+
|
200
|
+
We implement proper input validation and sanitization for all external inputs
|
201
|
+
via [pydantic](https://pydantic-docs.helpmanual.io/):
|
202
|
+
|
203
|
+
1. Validate inputs as early as possible in the data flow.
|
204
|
+
|
205
|
+
We handle authentication and authorization correctly:
|
206
|
+
|
207
|
+
1. Use industry-standard authentication protocols (OAuth, JWT).
|
208
|
+
2. Separate authentication from authorization logic.
|
209
|
+
3. Implement proper session management with secure cookies.
|
210
|
+
4. Protect against common vulnerabilities:
|
211
|
+
1. SQL Injection: Use parameterized queries or ORM frameworks.
|
212
|
+
2. XSS: Apply proper output encoding.
|
213
|
+
3. CSRF: Implement anti-CSRF tokens for state-changing operations.
|
214
|
+
4. SSRF: Validate and restrict URL destinations.
|
215
|
+
5. Command Injection: Avoid direct system command execution where possible.
|
216
|
+
5. Implement proper error handling that doesn't leak sensitive information.
|
217
|
+
6. Use secure defaults and fail closed (secure) rather than open (insecure).
|
218
|
+
|
219
|
+
We apply the principle of defense in depth:
|
220
|
+
|
221
|
+
1. Don't rely on a single security control.
|
222
|
+
2. Implement multiple layers of protection.
|
223
|
+
3. Document security considerations in code and design documents.
|
224
|
+
4. Write security-focused tests:
|
225
|
+
1. Test for security property violations.
|
226
|
+
2. Test error cases and edge conditions.
|
227
|
+
3. Test for resource exhaustion scenarios.
|
228
|
+
5. Apply proper rate limiting and throttling to prevent abuse.
|
229
|
+
6. For cryptographic operations:
|
230
|
+
1. Use established libraries, not custom implementations.
|
231
|
+
2. Follow current best practices for algorithm selection and key management.
|
232
|
+
3. Be aware of the limitations of cryptographic primitives.
|
233
|
+
7. Regularly run security-focused static analysis tools as part of CI/CD:
|
234
|
+
1. CodeQL analysis (via GitHub Actions)
|
235
|
+
2. SonarCloud checks for security vulnerabilities
|
236
|
+
|
237
|
+
Our security posture is defined in [SECURITY.md](SECURITY.md).
|
238
|
+
|
239
|
+
## Dependency Management
|
240
|
+
|
241
|
+
We use modern dependency management practices:
|
242
|
+
|
243
|
+
1. [uv](https://github.com/astral-sh/uv) for fast, reliable package installation
|
244
|
+
and environment management
|
245
|
+
2. Dependency version locking via uv.lock file
|
246
|
+
3. Regular dependency auditing:
|
247
|
+
1. Security auditing via `pip-audit`
|
248
|
+
2. License compliance checks via `pip-licenses`
|
249
|
+
3. SBOM generation via `cyclonedx-py`
|
250
|
+
|
251
|
+
Dependency updates are automated via Dependabot and Renovate to ensure we stay
|
252
|
+
current with security patches.
|
253
|
+
|
254
|
+
## Versioning
|
255
|
+
|
256
|
+
We use [semantic versioning](https://semver.org/) for versioning our releases:
|
257
|
+
|
258
|
+
1. MAJOR: Breaking changes
|
259
|
+
2. MINOR: New features, non-breaking changes
|
260
|
+
3. PATCH: Bug fixes, non-breaking changes
|
261
|
+
|
262
|
+
Our API versioning follows the same principles, with major versions indicated in
|
263
|
+
the URL (e.g., /api/v1/resource) and the full version provided as part of the
|
264
|
+
OpenAPI pecification.
|
265
|
+
|
266
|
+
## Conventional Commits
|
267
|
+
|
268
|
+
Our commit messages follow conventional commits format.
|
269
|
+
|
270
|
+
1. We use 'feat','fix','chore','docs','style','refactor','test' prefixes and
|
271
|
+
components in parentheses. E.g.
|
272
|
+
`feat(api): add new endpoint for user registration`.
|
273
|
+
|
274
|
+
## Guidance for AI Pair Programming
|
275
|
+
|
276
|
+
When generating code with AI assistance:
|
277
|
+
|
278
|
+
1. AI-generated code must follow all style guidelines in this document.
|
279
|
+
2. Always review AI-generated code for correctness, security implications, and
|
280
|
+
adherence to project patterns.
|
281
|
+
3. Use AI to generate tests alongside implementation code.
|
282
|
+
4. Request explanations for complex algorithms or patterns in the generated code.
|
283
|
+
5. Remember that AI should augment, not replace, human judgment about code
|
284
|
+
quality and design decisions.
|
@@ -55,8 +55,8 @@ examples/ # Example code demonstrating use of the project
|
|
55
55
|
Don't forget to configure your `.env` file with the required environment variables.
|
56
56
|
|
57
57
|
Notes:
|
58
|
-
|
59
|
-
|
58
|
+
1. .env.example is provided as a template.
|
59
|
+
2. .env is excluded from version control, so feel free to add secret values.
|
60
60
|
|
61
61
|
### update dependencies and create virtual environment
|
62
62
|
|
@@ -117,9 +117,8 @@ uv run nox -s act
|
|
117
117
|
```
|
118
118
|
|
119
119
|
Notes:
|
120
|
-
|
121
|
-
-
|
122
|
-
- test-and-report.yml calls all build steps defined in noxfile.py
|
120
|
+
1. Workflow defined in `.github/workflows/*.yml`
|
121
|
+
2. test-and-report.yml calls all build steps defined in noxfile.py
|
123
122
|
|
124
123
|
### Docker
|
125
124
|
|
@@ -147,10 +146,10 @@ uv run nox -s update_from_template
|
|
147
146
|
|
148
147
|
## Pull Request Guidelines
|
149
148
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
149
|
+
1. Before starting to write code read the [code style guide](CODE_STYLE.md) document for mandatory coding style
|
150
|
+
guidelines.
|
151
|
+
2. **Pre-Commit Hooks:** We use pre-commit hooks to ensure code quality. Please install the pre-commit hooks by running `uv run pre-commit install`. This ensure all tests, linting etc. pass locally before you can commit.
|
152
|
+
3. **Squash Commits:** Before submitting a pull request, please squash your commits into a single commit.
|
153
|
+
4. **Branch Naming:** Use descriptive branch names like `feature/your-feature` or `fix/issue-number`.
|
154
|
+
5. **Testing:** Ensure new features have appropriate test coverage.
|
155
|
+
6. **Documentation:** Update documentation to reflect any changes or new features.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: oe-python-template-example
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.6
|
4
4
|
Summary: 🧠 Example project scaffolded and kept up to date with OE Python Template (oe-python-template).
|
5
5
|
Project-URL: Homepage, https://oe-python-template-example.readthedocs.io/en/latest/
|
6
6
|
Project-URL: Documentation, https://oe-python-template-example.readthedocs.io/en/latest/
|
@@ -104,48 +104,126 @@ Description-Content-Type: text/markdown
|
|
104
104
|
---
|
105
105
|
|
106
106
|
|
107
|
-
Example project scaffolded and kept up to date with OE Python Template
|
108
|
-
|
107
|
+
Example project scaffolded and kept up to date with OE Python Template (oe-python-template).
|
108
|
+
|
109
|
+
This [Copier](https://copier.readthedocs.io/en/stable/) template enables you to quickly generate a Python package with fully functioning build and test automation.
|
110
|
+
Projects generated from this template can be [easily updated](https://copier.readthedocs.io/en/stable/updating/) to benefit from improvements and new features of the template.
|
111
|
+
|
112
|
+
Features:
|
113
|
+
1. Package management with [uv](https://github.com/astral-sh/uv)
|
114
|
+
2. Code formatting with [Ruff](https://github.com/astral-sh/ruff)
|
115
|
+
3. Linting with [Ruff](https://github.com/astral-sh/ruff)
|
116
|
+
4. Static type checking with [mypy](https://mypy.readthedocs.io/en/stable/)
|
117
|
+
5. Complete set of [pre-commit](https://pre-commit.com/) hooks including [detect-secrets](https://github.com/Yelp/detect-secrets) and [pygrep](https://github.com/pre-commit/pygrep-hooks)
|
118
|
+
6. Unit and E2E testing with [pytest](https://docs.pytest.org/en/stable/) including parallel test execution
|
119
|
+
7. Matrix testing in multiple environments with [nox](https://nox.thea.codes/en/stable/)
|
120
|
+
8. Test coverage reported with [Codecov](https://codecov.io/) and published as release artifact
|
121
|
+
9. CI/CD pipeline automated with [GitHub Actions](https://github.com/features/actions)
|
122
|
+
10. CI/CD pipeline can be run locally with [act](https://github.com/nektos/act)
|
123
|
+
11. Code quality and security checks with [SonarQube](https://www.sonarsource.com/products/sonarcloud) and [GitHub CodeQL](https://codeql.github.com/)
|
124
|
+
12. Dependency monitoring with [pip-audit](https://pypi.org/project/pip-audit/), [Renovate](https://github.com/renovatebot/renovate), and [GitHub Dependabot](https://docs.github.com/en/code-security/getting-started/dependabot-quickstart-guide)
|
125
|
+
13. Licenses of dependencies extracted with [pip-licenses](https://pypi.org/project/pip-licenses/) and published as release artifacts in CSV and JSON format for compliance checks
|
126
|
+
14. Software Bill of Materials (SBOM) generated with [cyclonedx-python](https://github.com/CycloneDX/cyclonedx-python) and published as release artifact
|
127
|
+
15. Version and release management with [bump-my-version](https://callowayproject.github.io/bump-my-version/)
|
128
|
+
16. Changelog and release notes generated with [git-cliff](https://git-cliff.org/)
|
129
|
+
17. Documentation generated with [Sphinx](https://www.sphinx-doc.org/en/master/) including reference documentation and PDF export
|
130
|
+
18. Documentation published to [Read The Docs](https://readthedocs.org/)
|
131
|
+
19. Interactive OpenAPI specification with [Swagger](https://swagger.io/)
|
132
|
+
20. Python package published to [PyPI](https://pypi.org/)
|
133
|
+
21. Docker images published to [Docker.io](https://hub.docker.com/) and [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry) with [artifact attestations](https://docs.github.com/en/actions/security-for-github-actions/using-artifact-attestations/using-artifact-attestations-to-establish-provenance-for-builds)
|
134
|
+
22. One-click development environments with [Dev Containers](https://code.visualstudio.com/docs/devcontainers/containers) and [GitHub Codespaces](https://github.com/features/codespaces)
|
135
|
+
23. Settings for use with [VSCode](https://code.visualstudio.com/)
|
136
|
+
24. Settings and custom instructions for use with [GitHub Copilot](https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot)
|
137
|
+
|
138
|
+
The generated project includes code, documentation and configuration of a fully functioning demo-application and service, which can be used as a starting point for your own project.
|
139
|
+
1. Service architecture suitable for use as shared library
|
140
|
+
2. Validation with [pydantic](https://docs.pydantic.dev/)
|
141
|
+
3. Command-line interface (CLI) with [Typer](https://typer.tiangolo.com/)
|
142
|
+
4. Versioned Web API with [FastAPI](https://fastapi.tiangolo.com/)
|
143
|
+
5. [Interactive Jupyter notebook](https://jupyter.org/) and [reactive Marimo notebook](https://marimo.io/)
|
144
|
+
6. Simple Web UI with [Streamlit](https://streamlit.io/)
|
145
|
+
7. Configuration to run the CLI and API in a Docker container including setup for [Docker Compose](https://docs.docker.com/get-started/docker-concepts/the-basics/what-is-docker-compose/)
|
146
|
+
8. Documentation including badges, setup instructions, contribution guide and security policy
|
147
|
+
|
148
|
+
Explore [here](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template-example) for what's generated out of the box.
|
149
|
+
|
150
|
+
## Generate a new project
|
151
|
+
|
152
|
+
This template is designed to be used with the [copier](https://copier.readthedocs.io/en/stable/) project generator. It allows you to create a new project based on this template and customize it according to your needs.
|
153
|
+
To generate a new project, follow these steps:
|
154
|
+
|
155
|
+
**Step 1**: Install uv package manager and copier. Copy the following code into your terminal and execute it.
|
156
|
+
```shell
|
157
|
+
if [[ "$OSTYPE" == "darwin"* ]]; then # Install dependencies for macOS X
|
158
|
+
if ! command -v brew &> /dev/null; then ## Install Homebrew if not present
|
159
|
+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
160
|
+
fi
|
161
|
+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then # Install dependencies for Linux
|
162
|
+
sudo apt-get update -y && sudo apt-get install curl -y # Install curl
|
163
|
+
fi
|
164
|
+
if ! command -v uvx &> /dev/null; then # Install uv package manager if not present
|
165
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
166
|
+
source $HOME/.local/bin/env
|
167
|
+
fi
|
168
|
+
uv tool install copier # Install copier as global tool
|
169
|
+
```
|
170
|
+
|
171
|
+
**Step 2**: [Create an empty repository on GitHub](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-new-repository), clone to your local machine, and change into it's directory.
|
172
|
+
|
173
|
+
**Step 3**: Generate the project. Copy
|
174
|
+
```shell
|
175
|
+
copier copy --trust gh:helmut-hoffer-von-ankershoffen/oe-python-template .
|
176
|
+
```
|
177
|
+
|
178
|
+
**Step 4**: Perform initial commit and push. Copy the following code into your terminal and execute it.
|
179
|
+
```shell
|
180
|
+
git add .
|
181
|
+
git commit -m "feat: Initial commit"
|
182
|
+
git push
|
183
|
+
```
|
184
|
+
|
185
|
+
Visit your GitHub repository and check the Actions tab. The CI workflow should already be running! The workflow will fail at the SonarQube step, as this external service is not yet configured for our new repository.
|
109
186
|
|
110
|
-
|
187
|
+
**Step 5**: Follow the [instructions](SERVICE_CONNECTIONS.md) to wire up
|
188
|
+
external services such as CloudCov, SonarQube Cloud, Read The Docs, Docker.io, and Streamlit Community Cloud.
|
111
189
|
|
112
|
-
|
113
|
-
|
190
|
+
**Step 6**: Release the first versions
|
191
|
+
```shell
|
192
|
+
./n bump
|
193
|
+
```
|
194
|
+
Notes:
|
195
|
+
1. You can remove this section post having successfully generated your project.
|
196
|
+
2. The following sections refer to the dummy application and service provided by this template.
|
197
|
+
Use them as inspiration and adapt them to your own project.
|
114
198
|
|
115
199
|
## Overview
|
116
200
|
|
117
|
-
Adding OE Python Template Example to your project as a dependency is easy.
|
201
|
+
Adding OE Python Template Example to your project as a dependency is easy. See below for usage examples.
|
118
202
|
|
119
203
|
```shell
|
120
204
|
uv add oe-python-template-example # add dependency to your project
|
121
205
|
```
|
122
206
|
|
123
|
-
If you don't have uv installed follow
|
124
|
-
|
125
|
-
If you still prefer pip over the modern and fast package manager
|
126
|
-
[uv](https://github.com/astral-sh/uv), you can install the library like this:
|
207
|
+
If you don't have uv installed follow [these instructions](https://docs.astral.sh/uv/getting-started/installation/). If you still prefer pip over the modern and fast package manager [uv](https://github.com/astral-sh/uv), you can install the library like this:
|
208
|
+
|
127
209
|
|
128
210
|
```shell
|
129
211
|
pip install oe-python-template-example # add dependency to your project
|
130
212
|
```
|
131
213
|
|
132
|
-
Executing the command line interface (CLI) in an isolated Python environment is
|
133
|
-
just as easy:
|
214
|
+
Executing the command line interface (CLI) in an isolated Python environment is just as easy:
|
134
215
|
|
135
216
|
```shell
|
136
|
-
uvx oe-python-template-example hello-world
|
137
|
-
uvx oe-python-template-example serve
|
138
|
-
uvx oe-python-template-example serve --port=4711 # serves
|
217
|
+
uvx oe-python-template-example hello-world # prints "Hello, world! [..]"
|
218
|
+
uvx oe-python-template-example serve # serves web API
|
219
|
+
uvx oe-python-template-example serve --port=4711 # serves web API on port 4711
|
139
220
|
```
|
140
221
|
|
141
222
|
Notes:
|
223
|
+
1. The API is versioned, mounted at `/api/v1` resp. `/api/v2`
|
224
|
+
2. While serving the web API go to [http://127.0.0.1:8000/api/v1/hello-world](http://127.0.0.1:8000/api/v1/hello-world) to see the respons of the `hello-world` operation.
|
225
|
+
3. Interactive documentation is provided at [http://127.0.0.1:8000/api/docs](http://127.0.0.1:8000/api/docs)
|
142
226
|
|
143
|
-
- The API is versioned, mounted at `/api/v1` resp. `/api/v2`
|
144
|
-
- While serving the webservice API go to
|
145
|
-
[http://127.0.0.1:8000/api/v1/hello-world](http://127.0.0.1:8000/api/v1/hello-world)
|
146
|
-
to see the respons of the `hello-world` operation.
|
147
|
-
- Interactive documentation is provided at
|
148
|
-
[http://127.0.0.1:8000/api/docs](http://127.0.0.1:8000/api/docs)
|
149
227
|
|
150
228
|
The CLI provides extensive help:
|
151
229
|
|
@@ -157,48 +235,31 @@ uvx oe-python-template-example openapi --help
|
|
157
235
|
uvx oe-python-template-example serve --help
|
158
236
|
```
|
159
237
|
|
238
|
+
|
160
239
|
## Operational Excellence
|
161
240
|
|
162
|
-
This project is designed with operational excellence in mind, using modern
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
-
|
178
|
-
|
179
|
-
|
180
|
-
- Compliant with modern linting and formatting standards (powered by
|
181
|
-
[Ruff](https://github.com/astral-sh/ruff))
|
182
|
-
- Up-to-date dependencies (monitored by
|
183
|
-
[Renovate](https://github.com/renovatebot/renovate) and
|
184
|
-
[GitHub Dependabot](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template-example/security/dependabot))
|
185
|
-
- [A-grade code quality](https://sonarcloud.io/summary/new_code?id=helmut-hoffer-von-ankershoffen_oe-python-template-example)
|
186
|
-
in security, maintainability, and reliability with low technical debt and
|
187
|
-
codesmell (verified by SonarQube)
|
188
|
-
- Additional code security checks using
|
189
|
-
[GitHub CodeQL](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template-example/security/code-scanning)
|
190
|
-
- [Security Policy](SECURITY.md)
|
191
|
-
- [License](LICENSE) compliant with the Open Source Initiative (OSI)
|
192
|
-
- 1-liner for installation and execution of command line interface (CLI) via
|
193
|
-
[uv(x)](https://github.com/astral-sh/uv) or
|
194
|
-
[Docker](https://hub.docker.com/r/helmuthva/oe-python-template-example/tags)
|
195
|
-
- Setup for developing inside a
|
196
|
-
[devcontainer](https://code.visualstudio.com/docs/devcontainers/containers)
|
197
|
-
included (supports VSCode and GitHub Codespaces)
|
241
|
+
This project is designed with operational excellence in mind, using modern Python tooling and practices. It includes:
|
242
|
+
|
243
|
+
1. Various examples demonstrating usage:
|
244
|
+
a. [Simple Python script](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template-example/blob/main/examples/script.py)
|
245
|
+
b. [Streamlit web application](https://oe-python-template-example.streamlit.app/) deployed on [Streamlit Community Cloud](https://streamlit.io/cloud)
|
246
|
+
c. [Jupyter](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template-example/blob/main/examples/notebook.ipynb) and [Marimo](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template-example/blob/main/examples/notebook.py) notebook
|
247
|
+
2. [Complete reference documentation](https://oe-python-template-example.readthedocs.io/en/latest/reference.html) on Read the Docs
|
248
|
+
3. [Transparent test coverage](https://app.codecov.io/gh/helmut-hoffer-von-ankershoffen/oe-python-template-example) including unit and E2E tests (reported on Codecov)
|
249
|
+
4. Matrix tested with [multiple python versions](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template-example/blob/main/noxfile.py) to ensure compatibility (powered by [Nox](https://nox.thea.codes/en/stable/))
|
250
|
+
5. Compliant with modern linting and formatting standards (powered by [Ruff](https://github.com/astral-sh/ruff))
|
251
|
+
6. Up-to-date dependencies (monitored by [Renovate](https://github.com/renovatebot/renovate) and [Dependabot](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template-example/security/dependabot))
|
252
|
+
7. [A-grade code quality](https://sonarcloud.io/summary/new_code?id=helmut-hoffer-von-ankershoffen_oe-python-template-example) in security, maintainability, and reliability with low technical debt and codesmell (verified by SonarQube)
|
253
|
+
8. Additional code security checks using [CodeQL](https://github.com/helmut-hoffer-von-ankershoffen/oe-python-template-example/security/code-scanning)
|
254
|
+
9. [Security Policy](SECURITY.md)
|
255
|
+
10. [License](LICENSE) compliant with the Open Source Initiative (OSI)
|
256
|
+
11. 1-liner for installation and execution of command line interface (CLI) via [uv(x)](https://github.com/astral-sh/uv) or [Docker](https://hub.docker.com/r/helmuthva/oe-python-template-example/tags)
|
257
|
+
12. Setup for developing inside a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) included (supports VSCode and GitHub Codespaces)
|
258
|
+
|
198
259
|
|
199
260
|
## Usage Examples
|
200
261
|
|
201
|
-
The following examples run from source
|
262
|
+
The following examples run from source - clone this repository using
|
202
263
|
`git clone git@github.com:helmut-hoffer-von-ankershoffen/oe-python-template-example.git`.
|
203
264
|
|
204
265
|
### Minimal Python Script:
|