USF-Python
Language: English|简体中文
USF Access Framework for Python
When the newest release only contains description updates, upload to PyPI will be failed.
Introduction
USF-Python is a Python library that provides access to the USF format for efficiency and universality.
Features
- Lightweight & Compact: Optimized for efficient storage and fast parsing.
- Supports Course Schedules: Store course names, instructors, locations, time slots, and week rules.
- Flexible Week Rules: Supports "all", "even", and "odd" week patterns.
- Simple API: Easy to read, write, and manipulate USF files.
- Cross-Platform: Works on all platforms supporting Python.
Installation
You can simply install the package with pip
pip install usf
or install it locally
python setup.py install
Usage
import usf
# Reading a USF file
data = usf.read("schedule.usf")
if usf.is_valid(data):
print("Valid USF file")
subjects = usf.get_subjects(data)
print(subjects)
else:
print("Invalid USF file")
# Creating a USF file
# Initialize the USF Generator (version 1 by default)
usf_generator = usf.USFGenerator()
# Add subjects
usf_generator.add_subject("Mathematics", simplified_name="Math", teacher="Dr. Smith", room="Room 101")
usf_generator.add_subject("Physics", simplified_name="Phys", teacher="Prof. Johnson", room="Room 203")
# Add class periods
usf_generator.add_period("08:00:00", "09:30:00")
usf_generator.add_period("10:00:00", "11:30:00")
# Add schedule entries
usf_generator.add_schedule(day=1, week_type="all", subject="Mathematics", period_index=1) # Monday
usf_generator.add_schedule(day=2, week_type="odd", subject="Physics", period_index=2) # Tuesday (Odd Week)
# Generate the USF data and save it to a file
usf_generator.save_to_file("schedule.usf")
# Adding a Course to an Existing USF File
data = usf.read("schedule.usf")
usf.add_subject(data, {
"name": "Physics",
"teacher": "Prof. Johnson",
"location": "Room 203",
"time": [3, 4],
"week": "odd"
})
usf.save(data, "updated_schedule.usf")
# Generating a USF File from Scratch
schedule = usf.create()
usf.add_subject(schedule, {
"name": "Computer Science",
"teacher": "Ms. Lee",
"location": "Lab 2",
"time": [5, 6],
"week": "even"
})
usf.save(schedule, "new_schedule.usf")
USF Format Specification
USF data is structured as a compact array:
- name: Course name (string)
- teacher: Instructor name (string)
- location: Classroom or venue (string)
- time: List of tuples representing periods, e.g.,
[(1, 2)]means periods 1 and 2 - week:
"all","even", or"odd"
Example JSON representation:
{
"version": 1,
"subjects": {
"Mathematics": {
"simplified_name": "Math",
"teacher": "Dr. Smith",
"room": "Room 101"
},
"Physics": {
"simplified_name": "Phys",
"teacher": "Prof. Johnson",
"room": "Room 203"
}
},
"periods": [
["08:00:00", "09:30:00"],
["10:00:00", "11:30:00"]
],
"timetable": [
[1, "all", "Mathematics", 1],
[2, "odd", "Physics", 2]
]
}
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.
License
This project is licensed under the MIT License.
Release files for usf 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| usf-0.2.0.tar.gz | 5.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| usf-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / usf-0.2.0.tar.gz
| Download URL | usf-0.2.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6fd322e4947be9903644ebe43dacb36b82f1e8c08fac850f1739a8a4a7ffb203
|
|
BLAKE2b-256 checksum How to use checksums |
216aad209978835ff92dd7c8f2fabd2e9e95867e26823a8ad00399d033ead938
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 13, 2025.
Transparency logRelease files / usf-0.2.0-py3-none-any.whl
| Download URL | usf-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c5a9509cc4a6aeb94f83f6300c1fb392b45eb92e59b5c641af504a4af194eb90
|
|
BLAKE2b-256 checksum How to use checksums |
accaa16f6461aea50c6cf301b4bfea512d455e1e7694aed003e5d51c7975adf2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 13, 2025.
Transparency log