Skip to main content

Make any module attributes read only.

Project description

License pypi version Repo Size Circle ci Build Status

readonly is a simple package to make any given module attributes into read only mode.

🛠️ Requirements

readonly requires Python 3.9 or above.

To install Python 3.9, I recommend using pyenv.

# install pyenv
git clone https://github.com/pyenv/pyenv ~/.pyenv

# setup pyenv (you should also put these three lines in .bashrc or similar)
# if you are using zsh
cat << EOF >> ~/.zshrc
# pyenv config
export PATH="${HOME}/.pyenv/bin:${PATH}"
export PYENV_ROOT="${HOME}/.pyenv"
eval "$(pyenv init -)"
EOF

# or if you using the default bash shell, do this instead:
cat << EOF >> ~/.bashrc
# pyenv config
export PATH="${HOME}/.pyenv/bin:${PATH}"
export PYENV_ROOT="${HOME}/.pyenv"
eval "$(pyenv init -)"
EOF
# Close and open a new shell session
# install Python 3.9.10
pyenv install 3.9.10

# make it available globally
pyenv global system 3.9.10

To manage the Python 3.9 virtualenv, I recommend using poetry.

# install poetry
curl -sSL https://install.python-poetry.org | python3 -
poetry --version
Poetry version 1.1.13

# Having the python executable in your PATH, you can use it:
poetry env use 3.9.10

# However, you are most likely to get the following issue:
Creating virtualenv readonly-dxc671ba-py3.9 in ~/.cache/pypoetry/virtualenvs

ModuleNotFoundError

No module named 'virtualenv.seed.via_app_data'

at <frozen importlib._bootstrap>:973 in _find_and_load_unlocked

# To resolve it, you need to reinstall virtualenv through pip
sudo apt remove --purge python3-virtualenv virtualenv
python3 -m pip install -U virtualenv

# Now, you can just use the minor Python version in this case:
poetry env use 3.9.10
Using virtualenv: ~/.cache/pypoetry/virtualenvs/readonly-dxc671ba-py3.9

🚨 Installation

With pip:

python3.9 -m pip install readonly

🚸 Usage

>>> from readonly import readonly
>>> import math
>>> math = readonly(math)

# raises AttributeError
>>> math.pi = 3.0

🎉 Credits

The following projects were used to build and test readonly.

👋 Contribute

If you are looking for a way to contribute to the project, please refer to the Guideline.

📝 License

This program and the accompanying materials are made available under the terms and conditions of the GNU GENERAL PUBLIC LICENSE.

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

readonly-0.1.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

readonly-0.1.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file readonly-0.1.2.tar.gz.

File metadata

  • Download URL: readonly-0.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.19.0-38-generic

File hashes

Hashes for readonly-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a2608fd5a355d42cb3ddb2de502a296be8a5ac9885c64d7002180e96cec02f6c
MD5 332f280547e3b5a7359b0001269a481d
BLAKE2b-256 02924ec1230d43fe7f93ef6dc00e5ecf33013e47875fa24fb4000de81b00c358

See more details on using hashes here.

File details

Details for the file readonly-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: readonly-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.19.0-38-generic

File hashes

Hashes for readonly-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c95cd593bb1fc62f842c357e9a15c47af009e91de5b9c8acc7f9ac4534ca3d11
MD5 3066c985aefbcbc95ceb834c8044177d
BLAKE2b-256 82f623cba74140a256a5f44ffdb7a00b868ec2c37f9764e095e15e9b33516775

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