Skip to main content

do-relative

Open and import relatively. Open files relative to the module you are in, instead of __main__ module. Import modules relatively, directly using import module syntax, without using the from . syntax. Or use from . even if you are not in a package. Import relative to given custom paths, including root directory so you can do an absolute import.

Installation

pip install do-relative

Api Reference

class do_relative.RelativeOpener()

Constructor of this class returns an open function, instead of its instance. The paths you give to this function will be treated as relative to the directory calling module resides in.

do_relative.relative_import(import_statement, folder = None)

Executes the import_statement in caller's scope and relative to the calling module's location. Calling this function from another function is not supported. In that case, no new names will be introduced to caller's scope. import_statement must be a string. Examples: "import module", "from module import func" or "from .. import module". As a side note, you don't have to be in a package to use the syntax shown in the last example. If supplied, folder must be a path string. If folder is provided import will be relative to that path instead of calling module's location. folder can either be relative to current working directory or absolute. You can pass "/" as the folder and make an absolute import. On windows "/" will be converted to the root directory of some drive. Drive is determined by the current working directory.

Metadata

Release files for do-relative 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for do-relative 1.0.0
File Size Uploaded
do_relative-1.0.0.tar.gz 2.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for do-relative 1.0.0
File Interpreter ABI Platform
do_relative-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 4.5 kB

Release files / do_relative-1.0.0.tar.gz

Download URL do_relative-1.0.0.tar.gz
Size 2.0 kB
Tags Source
SHA-256 checksum
How to use checksums
19b3bf35442105d89df8fd7bc73c12655a940fdcf95f5dd2da9319aa476b3832
BLAKE2b-256 checksum
How to use checksums
834ef018783c0b1ea3497677babf78f54bbaf1cb3f922404f703281648a95307
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Release files / do_relative-1.0.0-py2.py3-none-any.whl

Download URL do_relative-1.0.0-py2.py3-none-any.whl
Size 2.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
51c54d098a79edfe736719db1a86add751a15bc8ba3a491bace29e4f4fc24114
BLAKE2b-256 checksum
How to use checksums
de81579cc38d9306783407e7924cccd02895587e12171611f12485428bd56dca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page