parent-lookup
Python package enabling a child object to dynamically lookup its parent at runtime. This allows bidirectional parent-child relationships without hard-coded circular dependencies or circular imports.
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.5%) to scientific vocabulary
Repository
Python package enabling a child object to dynamically lookup its parent at runtime. This allows bidirectional parent-child relationships without hard-coded circular dependencies or circular imports.
Basic Info
- Host: GitHub
- Owner: ClaasRostock
- License: mit
- Language: Python
- Default Branch: main
- Size: 230 KB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 3
Metadata Files
README.md
parent-lookup
parent-lookup is a utility Python package enabling a child object to dynamically lookup its parent at runtime.
It comprises of a small set of decorators and methods allowing bidirectional parent-child relationships without hard-coded circular dependencies or circular imports.
Installation
sh
pip install parent-lookup
Usage Example
API:
```py from parentlookup import TParent, ischildlookup, lookupregistry
class Child: def init(self) -> None: pass
@overload
def find_parent(self, parent_type: type[TParent]) -> TParent | None:
pass
@overload
def find_parent(self, parent_type: TParent) -> TParent | None:
pass
def find_parent(self, parent_type: type[TParent] | TParent) -> TParent | None:
return lookup_registry.lookup_parent(self, parent_type)
class Parent: def init(self) -> None: self._childs: list[Child] = []
def __new__(
cls,
) -> Parent:
instance = super().__new__(cls)
lookup_registry.register_parent(instance)
return instance
def add_child(self, child: Child) -> None:
self._childs.append(child)
@property
@is_child_lookup
def childs(self) -> list[Child]:
return self._childs
Create two objects: A parent object and a child object
parent = Parent() child = Child()
Add child to parent
parent.add_child(child)
Lookup parent from child
foundparent = child.findparent(Parent) assert found_parent is parent ```
For more examples and usage, please refer to parent-lookup's documentation.
Development Setup
1. Install uv
This project uses uv as package manager.
If you haven't already, install uv, preferably using it's "Standalone installer" method:
..on Windows:
sh
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
..on MacOS and Linux:
sh
curl -LsSf https://astral.sh/uv/install.sh | sh
(see docs.astral.sh/uv for all / alternative installation methods.)
Once installed, you can update uv to its latest version, anytime, by running:
sh
uv self update
2. Install Python
This project requires Python 3.10 or later.
If you don't already have a compatible version installed on your machine, the probably most comfortable way to install Python is through uv:
sh
uv python install
This will install the latest stable version of Python into the uv Python directory, i.e. as a uv-managed version of Python.
Alternatively, and if you want a standalone version of Python on your machine, you can install Python either via winget:
sh
winget install --id Python.Python
or you can download and install Python from the python.org website.
3. Clone the repository
Clone the parent-lookup repository into your local development directory:
sh
git clone https://github.com/ClaasRostock/parent-lookup path/to/your/dev/parent-lookup
Change into the project directory after cloning:
sh
cd parent-lookup
4. Install dependencies
Run uv sync to create a virtual environment and install all project dependencies into it:
sh
uv sync
Note: Using
--no-devwill omit installing development dependencies.Note:
uvwill create a new virtual environment called.venvin the project root directory when runninguv syncthe first time. Optionally, you can create your own virtual environment using e.g.uv venv, before runninguv sync.
6. (Optional) Activate the virtual environment
When using uv, there is in almost all cases no longer a need to manually activate the virtual environment.
uv will find the .venv virtual environment in the working directory or any parent directory, and activate it on the fly whenever you run a command via uv inside your project folder structure:
sh
uv run <command>
However, you still can manually activate the virtual environment if needed.
When developing in an IDE, for instance, this can in some cases be necessary depending on your IDE settings.
To manually activate the virtual environment, run one of the "known" legacy commands:
..on Windows:
sh
.venv\Scripts\activate.bat
..on Linux:
sh
source .venv/bin/activate
7. Install pre-commit hooks
The .pre-commit-config.yaml file in the project root directory contains a configuration for pre-commit hooks.
To install the pre-commit hooks defined therein in your local git repository, run:
sh
uv run pre-commit install
All pre-commit hooks configured in .pre-commit-config.yaml will now run each time you commit changes.
pre-commit can also manually be invoked, at anytime, using:
sh
uv run pre-commit run --all-files
To skip the pre-commit validation on commits (e.g. when intentionally committing broken code), run:
sh
uv run git commit -m <MSG> --no-verify
To update the hooks configured in .pre-commit-config.yaml to their newest versions, run:
sh
uv run pre-commit autoupdate
8. Test that the installation works
To test that the installation works, run pytest in the project root folder:
sh
uv run pytest
Meta
Copyright (c) 2025 Claas Rostock. All rights reserved.
Claas Rostock - @LinkedIn - claas.rostock@dnv.com
Distributed under the MIT license. See LICENSE for more information.
https://github.com/ClaasRostock/parent-lookup
Contributing
- Fork it (https://github.com/ClaasRostock/parent-lookup/fork)
- Create an issue in your GitHub repo
- Create your branch based on the issue number and type (
git checkout -b issue-name) - Evaluate and stage the changes you want to commit (
git add -i) - Commit your changes (
git commit -am 'place a descriptive commit message here') - Push to the branch (
git push origin issue-name) - Create a new Pull Request in GitHub
For your contribution, please make sure you follow the STYLEGUIDE before creating the Pull Request.
Owner
- Name: Claas Rostock
- Login: ClaasRostock
- Kind: user
- Repositories: 1
- Profile: https://github.com/ClaasRostock
Citation (CITATION.cff)
title: parent-lookup
version: 0.2.0
abstract: >-
Python package enabling a child object to dynamically lookup its parent at runtime.
type: software
authors:
- given-names: Claas
family-names: Rostock
affiliation: DNV
email: claas.rostock@dnv.com
website: 'https://www.linkedin.com/in/claasrostock/?locale=en_US'
keywords:
- parent
- child
- lookup
license: MIT
license-url: 'https://ClaasRostock.github.io/parent-lookup/LICENSE.html'
url: 'https://ClaasRostock.github.io/parent-lookup/README.html'
repository-code: 'https://github.com/ClaasRostock/parent-lookup'
message: 'Please cite this software using these metadata.'
cff-version: 1.2.0
GitHub Events
Total
- Release event: 3
- Delete event: 1
- Issue comment event: 1
- Push event: 180
- Pull request event: 1
- Pull request review event: 1
- Create event: 7
Last Year
- Release event: 3
- Delete event: 1
- Issue comment event: 1
- Push event: 180
- Pull request event: 1
- Pull request review event: 1
- Create event: 7
Issues and Pull Requests
Last synced: 7 months ago
All Time
- Total issues: 0
- Total pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: 2 minutes
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 1.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: 2 minutes
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 1.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- ClaasRostock (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 18 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 3
- Total maintainers: 1
pypi.org: parent-lookup
Python package enabling a child object to dynamically lookup its parent at runtime.
- Homepage: https://github.com/ClaasRostock/parent-lookup
- Documentation: https://ClaasRostock.github.io/parent-lookup/README.html
- License: MIT License Copyright (c) 2025 Claas Rostock Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
Latest release: 0.2.0
published about 1 year ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v4 composite
- actions/setup-python v5 composite
- astral-sh/setup-uv v5 composite
- peaceiris/actions-gh-pages v4 composite
- sphinx-doc/github-problem-matcher master composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- actions/upload-artifact v4 composite
- astral-sh/setup-uv v5 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- astral-sh/setup-uv v5 composite
- actions/checkout v4 composite
- devmasx/merge-branch v1.4.0 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- astral-sh/setup-uv v5 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- astral-sh/setup-uv v5 composite
- actions/download-artifact v4 composite
- pypa/gh-action-pypi-publish release/v1 composite
- typing-inspect >=0.9.0