The Library System is a Python application designed to manage a library's books, loans, and borrowers. The application uses PostgreSQL as its database backend and provides a command-line interface (CLI) to interact with the system. You can add, modify, and delete books, borrowers, and manage loans. This application also supports test environments, ensuring that the functionality is thoroughly verified.
Before running the application, make sure you have PostgreSQL and Python installed and running on your system.
Clone the repository:
git clone https://github.com/m-grande/library-system.git
cd library-system
Open your terminal and launch psql to interact with PostgreSQL:
psql
Create two local databases - one for production and one for testing:
CREATE DATABASE library_db;
CREATE DATABASE library_test_db;
Once the databases have been created, exit psql by running:
\q
For each database, initialize the table structures using the init.sql file:
psql -d library_db -U your_username -h localhost -f db/init.sql
psql -d library_test_db -U your_username -h localhost -f db/init.sql
Next, import the data for authors, genres, books, and borrowers into the library_db:
psql -d library_db -U your_username -h localhost -f db/data/authors.sql
psql -d library_db -U your_username -h localhost -f db/data/genres.sql
psql -d library_db -U your_username -h localhost -f db/data/books.sql
psql -d library_db -U your_username -h localhost -f db/data/borrowers.sql
Modify the DATABASE_CONFIG in app/db_connection.py. Replace your_username with your PostgreSQL username:
DATABASE_CONFIG = {
"production": {
"dbname": "library_db",
"user": "your_username",
"host": "localhost",
"port": "5432",
},
"test": {
"dbname": "library_test_db",
"user": "your_username",
"host": "localhost",
"port": "5432",
}
}It's recommended to run the application in a virtual environment:
-
Create a virtual environment:
python3 -m venv venv -
Activate the virtual environment:
source venv/bin/activate -
To deactivate the virtual environment, run:
deactivate
Install the required Python dependencies:
pip install -r requirements.txt
To run the application in the production environment, use:
ENV=production python3 -m app.cli
To run the test suite, use the following command:
ENV=test pytest -v
- Make sure your PostgreSQL server is running and accessible at
localhoston port5432. - The test database (
library_test_db) is used to isolate test runs from the production database. - The CLI allows for easy management of the library, including adding books, borrowers, and managing loans.
If you encounter any issues or have questions, feel free to raise an issue or contribute to the project.