Skip to main content

Share packages for monorepo services

Project description

sharedlib

Pythonic way for use "shared" folder of packages (utils).

Usage

First, we need to import “sharedlib” into the file where we will use the shared packages:

import sharedlib

Then import a “shared” package with the same name as specified in the config settings:

import my_shared_pkg
from my_shared_pkg import a, b, c
from my_shared_pkg.a.b.c import d

And it's working! Python registers a package with the specified name and you can use that in your files.

A complete example:

# file: service1/routes/admin.py
import sharedlib

# file: service2/models/user.py
import sharedlib

# original folder: custom_shared/
import my_shared_pkg

# original folders: custom_shared/a, custom_shared/b, custom_shared/c
from my_shared_pkg import a, b, c

# original folder: custom_shared/a/b/c, file: d.py
from my_shared_pkg.a.b.c import d

print(a, b, c, d)

Configuration file

sharedlib.ini

To work with “sharedlib” it is necessary to specify the file sharedlib.ini in the root of the project (repository):

[sharedlib]
folder_name = custom_shared
import_name = my_shared_pkg

If the file is not found, an exception will be raised.

Important: The configuration file must be located in the root of the project. Otherwise imports will not work properly.

pyproject.toml

You can also use pyproject.toml for customization:

[tool.sharedlib]
folder_name = "custom_shared"
import_name = "my_shared_pkg"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sharedlib-0.0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

sharedlib-0.0.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file sharedlib-0.0.1.tar.gz.

File metadata

  • Download URL: sharedlib-0.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.18

File hashes

Hashes for sharedlib-0.0.1.tar.gz
Algorithm Hash digest
SHA256 410b790987c348269bac9a5df297da8886316234745b37d6d82f6e8074141709
MD5 ca69532e65931dccc60ce8b65cf8e665
BLAKE2b-256 bb815cb485d60a182949a0d419bb053a1060f3ef034c7d39d1c94302974bd0ec

See more details on using hashes here.

File details

Details for the file sharedlib-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sharedlib-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f9ca44fed807ac7a09b1c1f5b8cbf7456f399ec5b327cf61a62e460d8723db66
MD5 bd98668c7711fd4701a34459dea22596
BLAKE2b-256 0d0ae1cec8f2b0ed155f821a998585371014e1e1063e01d0da801d3c84cd7a9c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page