PyBookLib is a two part library designed to host and get template code projects. It is written for mainly Python programs, but it is possible to host other languages as well. PyBookLib has two submodules, each independant of one another: PyBook and PyLib. PyBookLib has no affiliations with the existing PyPI projects PyBook and PyLib. It is a completely separated project, and just happened to be library themed. ?
You can install the package through the following:
pip install -U PyBookLib
If you want the latest development version, which most definitely has bugs, run the following:
pip install git+https://github.com/BD103/PyBookLib
To pull up this markdown file in the console, you can run PyBookLib
in the command line. Running pybook
or pylib
gives a list of possible commands with each.
The main PyBookLib module has no current function beyond a code bridge and displaying this markdown file in the command line.
PyBookLib
PyBook's main functionality is connecting to a hosted library and receiving books (.zip
files). The library that is accessed is defined by an environmental variable. Try running something like this:
from PyBookLib import pybook
import os
# Set environmental variable for library. Unecessary but helpful all the same
pybook.set_url("https://library.bd103.repl.co/api")
# Gets a book "sample-library" from the user "BD103" with the version "1.2" and extracts contents to the directory "pylib-library"
pybook.get(user="BD103", book="sample-library", version="1.2", direc="pylib-library")
With this simple script, it connects to library.bd103.repl.co and requests sample-library. This book is a sample script to host your own library. (It was created for Replit, so that's why there is a pyproject.toml.)
You can also run some bash commands:
# Get a list of commands
pybook --help
pybook get-book BD103 sample-library --version 1.2 --direc pylib-library
pybook get-user BD103
# This should automatically be set to library.bd103.repl.co/api
pybook set-url https://link.to.site/api
# Umbrella get function to specify exact details
pybook get --user BD103 --direc folder
You do not have to specify all these parameters. Try removing and replacing some of them and see what happens!
PyLib is for hosting your own library. It is extremely simple. Install PyBookLib, and choose your path:
Note: These paths will automatically set the IP and Port to
0.0.0.0:8000
. If on a local machine, you can connect through localhost:8000. If using a server hosting service, it should automatically set the host to your domain. If you are having conflicts with the port, or want a different IP, you can specify it by taking the Python main.py path and replacingpylib.run()
withpylib.run(host="1.2.3.4", port=8080)
.
Create a file called main.py. Inside, paste the following:
from PyBookLib import pylib
pylib.run()
Run the script to start hosting your library.
In the command line, run the following:
pylib run
Watch as your server gets hosted.
If you want to contribute to this project, go to github.com/BD103/PyBookLib, create a fork and a pull request. All code should be run through the following commands:
black PyBookLib
isort PyBookLib --profile black
flake8 PyBookLib
PyTest is not yet implemented. Stay tuned! ?