Skip to main content

A example of a nested package

Project description

Introduction

A template of a python project with nested packages.

Project structure:

Python allows flexibity in defining the structure of the project, Here we show an example:

  • LICENSE.md: Your project's license.
  • README.md: A description of your project and its goals.
  • .gitignore: A file that tells Git what files and directories to ignore.
  • example_pkg: A directory with the name of your project.
  • requirements.txt: A file where you can defines outside Python dependencies and their versions for your package.
├── docs
├── example_pkg                 Top-level package
│   ├── __about__.py
│   ├── core.py
│   ├── __init__.py
│   ├── sub_pkg_1
│   │   ├── __init__.py
│   │   ├── mod_one.py
│   │   ├── mod_two.py
│   │   └── nested_pkg_1
│   │       ├── __init__.py
│   │       └── nst_1.py
│   ├── sub_pkg_2
│   │   ├── __init__.py
│   │   ├── mod_1.py
│   │   └── mod_2.py
│   └── supporters.py
├── .gitignore                  
├── LICENSE
├── README.md
├── requirements.txt
├── setup.py
└── tests


Importing functions:

What is imported in __init__.py ; can be called using the dot notation when the directory is imported as package. for example, in the nested_pkg_1 directory we import nested_function() from nst_1.py in nested_pkg_1/__init__.py

# nested_pkg_1/__init__.py
# Import functions from the modules in the package nested_pkg_1
from example_pkg.sub_pkg_1.nested_pkg_1.nst_1 import nested_function

Importing modules:

Importing packages:

Then in sub_pkg_1/init.py, Then we import the nested_pkg_1

# Import nested_pkg_1
from example_pkg.sub_pkg_1 import nested_pkg_1

When nested_pkg_1 package is imported, nested_function can be called from nested_pgk_1 in example_pkg/core.py

# from example_pkg import sub_pkg_1
sub_pkg_1.nested_pkg_1.nested_function()

Testing

References

Install

in setup folder run pip install .

WARNING: using python setup.py install

the package doesnot show through conda list Note: Avoid using python setup.py install use pip install . [https://stackoverflow.com/questions/1550226/python-setup-py-uninstall]

#TODO try generating wheel and installing the file

python3 setup.py sdist bdist_wheel

https://packaging.python.org/tutorials/packaging-projects/

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

firstNestedPackage-edo-0.0.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

firstNestedPackage_edo-0.0.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file firstNestedPackage-edo-0.0.0.tar.gz.

File metadata

  • Download URL: firstNestedPackage-edo-0.0.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for firstNestedPackage-edo-0.0.0.tar.gz
Algorithm Hash digest
SHA256 1745c6b3719e62dea8965a784f86397971e8aca12cd4a8c58f93458105564d6f
MD5 e996556745bef79f81213409bf6ee796
BLAKE2b-256 6bd9bc166250e868d50249224a5064beb81c5227ca85bc807318d1c2ab97630c

See more details on using hashes here.

File details

Details for the file firstNestedPackage_edo-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: firstNestedPackage_edo-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for firstNestedPackage_edo-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4f21f7147f1603034afdb3c4cc65af3f6b81f2c584544525fc5ea985200c30b
MD5 065ca80c13de743e6075d674da80eba1
BLAKE2b-256 55e2f3c397634f5983ef9babd94bf4a001da51904b9d8c0f709f422329ac0c8e

See more details on using hashes here.

Supported by

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