Skip to main content

InlineImporter

InlineImporter is a library for python projects that uses the PEP 302 import protocol to inline libraries into a script.

Why?

Because we can.

But in all seriousness, this came out from spending days managing adhoc scripts that shared a lot of functionality. For ease of development, it would have been nice to extract the common pieces to a common library, but that would have meant distributing a whole directory and managing import paths on the destination systems versus a single self-contained file.

How it works

PEP 302 defined a protocol for managing module imports. The protocol defines two components: Finders and Loaders. The Finder is responsible for, unsurprisingly, finding modules. If a Finder finds a module, i.e. knows which loader can load a module, it returns a ModuleSpec. This ModuleSpec gives details on some parameters of the module, such as filename and package, and states which Loader can load the module. The Loader is, as you've guessed it, responsible for loading modules into the environment. It does so by first creating a module object, which the python machinery places into the sys.modules dictionary, then executing the module code. An object that can both Find and Load is called an Importer.

InlineImporter works by placing the source code of modules in a dictionary, keyed by module name. The finder searche the dictionary for a key matching the given module name. If found, it returns a ModuleSpec with itself listed as the loader. The loader simply compiles the inlined source code to python bytecode, and executes it as the normal python loader does.

Usage

Include inline-importer in your development dependencies. inline-importer is not a runtime dependency, but a build-time dependency instead.

Build your final script using inline-python or python -m inline_importer and distribute the output of that instead.

Your users will not require inline-importer. However, if you have dependencies on other modules, your users will have to install those.

What's next

While the importer is built, the rest of the machinery isn't.

  • Importer with PoC.
  • Script to collect all the modules to be inlined and build the dictionary.
  • Script that can combine the importer and the modules.
  • Support for inlining distributed python libraries.
  • Support for pre-compiled bytecode.

Metadata

Release files for inline-importer 0.0.4

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

Source distribution (sdist)

Source distribution for inline-importer 0.0.4
File Size Uploaded
inline-importer-0.0.4.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for inline-importer 0.0.4
File Interpreter ABI Platform
inline_importer-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / inline-importer-0.0.4.tar.gz

Download URL inline-importer-0.0.4.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
db1e9394254e8255b1b61c62b0f7e6d4b8872c1d40946a9cd8c6780c7dbfb3b4
BLAKE2b-256 checksum
How to use checksums
f5178d199d9198a0b8d8fa4b9955d32a3be79cb27745a5760c8b95687fd20372
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

Release files / inline_importer-0.0.4-py3-none-any.whl

Download URL inline_importer-0.0.4-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
145711731cf5daac46ee621b7c7208a779da21bb2c2893af7352db90c52c12db
BLAKE2b-256 checksum
How to use checksums
ef39be7c86e85d526e6e65a2bec44e226337cd8bb43a146f50281f5b25b1cb46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.1

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