Skip to main content

A dynamic table creation and management library for PostgreSQL

Project description

Dynamic Tables (Python)

A Python library for dynamically creating and managing PostgreSQL tables based on input data.


🚀 Features

  • Automatically creates tables based on incoming data.
  • Supports dynamic naming conventions.
  • Provides easy database connectivity with PostgreSQL.
  • Includes helper functions for querying and deleting tables.

📥 Installation

1️⃣ Install via GitHub (Recommended for Development)

Clone the repository and install in editable mode:

git clone https://github.com/scottrodeo/dynamic-tables-python.git
cd dynamic-tables-python
pip install -e .

2️⃣ Install Directly via pip

The package is available on PyPI, install it with:

pip install dynamic-tables

🏃‍♂️ Running the Example

1️⃣ Quick Run (Without Installation)

Run the example script directly:

python3 examples/example.py

💡 This works because the script dynamically adjusts sys.path.


📌 Example Usage

Once installed, you can use dynamic_tables in your Python scripts:

from dynamic_tables import DynamicTables

# Initialize the dynamic table manager
tables = DynamicTables()

# Configure dynamic table properties
tables.set_table_prefix("dtbl_")
tables.set_columns("domain TEXT, category TEXT, lang TEXT")
tables.set_dynamic_column("domain")

# Insert dynamic data
tables.input("wikipedia.org", "cats", "en")
tables.input("wikipedia.org", "dogs", "en")

# Show all tables
tables.show_tables()

🛠️ Available Functions

Function Description
set_columns("name TYPE, age TYPE") Define table schema
set_table_prefix("prefix_") Set a custom table prefix
set_dynamic_column("column_name") Set the column that determines dynamic table names
input(value1, value2, ...) Insert a new row dynamically
show_tables() List all dynamically created tables
show_columns("table_name") Show column details for a specific table
show_columns_all() Show column details for all tables
select_table("table_name") Retrieve all rows from a table
delete_tables() Drop all tables matching the prefix
create_table("table_name", [("column1", "TYPE"), ("column2", "TYPE")]) Create a table dynamically
insert_data("table_name", {"column1": value1, "column2": value2}) Insert data into a specific table
get_tables() Retrieve a list of all tables in the database
get_columns("table_name") Retrieve all columns for a given table
get_table_rows("table_name") Retrieve all rows from a table
connectHC("dbname", "user", "password", "host") Connect using hardcoded credentials
connectJSON("config.json") Connect using credentials from a JSON config file
connectENVS() Connect using environment variables
connection_open("dbname", "user", "password", "host") Open a PostgreSQL database connection
connection_close() Close the database connection
status() Show the current configuration status
show_db() Display the connected database name
setup_logging(level, log_to_file) Configure logging settings
change_log_level("LEVEL") Change the logging level at runtime
show_version() Display the current version of the library

⚡ Development

Running Tests

Run the test suite:

pytest tests/

Linting

Ensure your code follows best practices:

flake8 dynamic_tables/

🤝 Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -m "Added new feature").
  4. Push to the branch (git push origin feature-branch).
  5. Open a pull request.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


🌎 Links


🚀 Happy Coding!

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

dynamic_tables-0.2.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

dynamic_tables-0.2.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file dynamic_tables-0.2.0.tar.gz.

File metadata

  • Download URL: dynamic_tables-0.2.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for dynamic_tables-0.2.0.tar.gz
Algorithm Hash digest
SHA256 030be62039a93f63f1384196446e805b43cd38dcb423cfae3c91afb8e8119a71
MD5 2cc84f9932c73356439352a8ed5b3455
BLAKE2b-256 17e66d3de64a441fb7667ca7c02a810842f3129d4fb201f055f7b861a693457d

See more details on using hashes here.

File details

Details for the file dynamic_tables-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dynamic_tables-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for dynamic_tables-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e365f45e00f78a428c207cb071e85adbe1db9af1811a6975c9c50f0952c9c23
MD5 83f4bac403b3c455ba659810712e404b
BLAKE2b-256 de5d0ab80730a97da0a59e15944ffd295aa2474f186eca3d2d539784059f6264

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