https://github.com/ctsit/pyutils
https://github.com/ctsit/pyutils
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ctsit/pyutils
- Owner: ctsit
- Created: 2023-08-03T12:56:13.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-16T12:54:06.000Z (about 2 years ago)
- Last Synced: 2025-02-27T20:32:35.795Z (over 1 year ago)
- Language: Python
- Size: 60.5 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# PyUtils
PyUtils is a collection of utility python functions for use across CTS-IT python projects.
## Installation
### Necessary requirements
`PyCustodian` depends on [`poetry`](https://python-poetry.org). Follow the instructions on our [Wiki](https://wiki.ctsi.ufl.edu/books/python/page/how-to-install-poetry)
### Setup
1. Make sure you have Python 3 installed on your machine.
1. Clone or download the repository to your local machine:
- `git clone git@github.com:ctsit/PyUtils.git`
1. Install the required dependencies by running the following command in the terminal:
- `poetry install`
## Example Usage
```python
from datetime import datetime
from py_utils.orm import DbClient
from py_utils import utils
from sqlmodel import Field, SQLModel
from typing import Optional
class Image(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
created_date: datetime = Field(default=datetime.utcnow(), nullable=False)
modified_date: datetime = Field(default_factory=datetime.utcnow, nullable=False)
core: str
directory: str
image_type: str
def main():
db_client = DbClient.sqlite("test_db.db")
db_client.create_tables()
# create dummy data
for i in range(10):
data_to_insert = {
core: f"title: ${i}",
directory: "",
image_type: "mri",
}
new_image = Image(**data_to_insert)
db_client.insert_data(image)
inserted_data = db_client.query_model(Image) # returns an `Image` class
# optionally send email
# utils.send_email()
```