OpenPartsLibrary 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openpartslibrary/__init__.py +0 -0
- openpartslibrary/db.py +87 -0
- openpartslibrary/models.py +71 -0
- openpartslibrary-0.1.0.dist-info/METADATA +20 -0
- openpartslibrary-0.1.0.dist-info/RECORD +8 -0
- openpartslibrary-0.1.0.dist-info/WHEEL +5 -0
- openpartslibrary-0.1.0.dist-info/licenses/LICENSE +21 -0
- openpartslibrary-0.1.0.dist-info/top_level.txt +1 -0
File without changes
|
openpartslibrary/db.py
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
from sqlalchemy import create_engine
|
2
|
+
from sqlalchemy.orm import sessionmaker
|
3
|
+
|
4
|
+
import pandas as pd
|
5
|
+
|
6
|
+
from datetime import datetime
|
7
|
+
|
8
|
+
from .models import Base, Part
|
9
|
+
|
10
|
+
|
11
|
+
class PartsLibrary:
|
12
|
+
def __init__(self):
|
13
|
+
import os
|
14
|
+
sqlite_path = os.path.join(os.path.dirname(__file__), 'data', 'parts.db')
|
15
|
+
print(sqlite_path)
|
16
|
+
self.engine = create_engine('sqlite:///' + sqlite_path)
|
17
|
+
|
18
|
+
Base.metadata.create_all(self.engine)
|
19
|
+
|
20
|
+
self.session_factory = sessionmaker(bind=self.engine)
|
21
|
+
self.session = self.session_factory()
|
22
|
+
|
23
|
+
def display(self):
|
24
|
+
part_table = pd.read_sql_table(table_name="parts", con=self.engine)
|
25
|
+
|
26
|
+
pd.set_option('display.max_columns', 8)
|
27
|
+
pd.set_option('display.width', 240)
|
28
|
+
|
29
|
+
print(part_table)
|
30
|
+
|
31
|
+
def display_reduced(self):
|
32
|
+
part_table = pd.read_sql_table(table_name="parts", con=self.engine)
|
33
|
+
reduced_part_table = part_table[["id", "number", "name", "quantity", "mass", "lead_time", "supplier", "unit_price", "currency"]]
|
34
|
+
pd.set_option('display.max_columns', 9)
|
35
|
+
pd.set_option('display.width', 200)
|
36
|
+
print(reduced_part_table)
|
37
|
+
|
38
|
+
|
39
|
+
def delete_all(self):
|
40
|
+
self.session.query(Part).delete()
|
41
|
+
self.session.commit()
|
42
|
+
|
43
|
+
def create_parts_from_spreadsheet(self, file_path):
|
44
|
+
df = pd.read_excel(file_path)
|
45
|
+
|
46
|
+
parts = []
|
47
|
+
for _, row in df.iterrows():
|
48
|
+
part = Part(
|
49
|
+
uuid=row["uuid"],
|
50
|
+
number=row["number"],
|
51
|
+
name=row["name"],
|
52
|
+
description=row.get("description", "No description"),
|
53
|
+
revision=str(row.get("revision", "1")),
|
54
|
+
lifecycle_state=row.get("lifecycle_state", "In Work"),
|
55
|
+
owner=row.get("owner", "system"),
|
56
|
+
date_created=row.get("date_created", datetime.utcnow()),
|
57
|
+
date_modified=row.get("date_modified", datetime.utcnow()),
|
58
|
+
material=row.get("material"),
|
59
|
+
mass=row.get("mass"),
|
60
|
+
dimension_x=row.get("dimension_x"),
|
61
|
+
dimension_y=row.get("dimension_y"),
|
62
|
+
dimension_z=row.get("dimension_z"),
|
63
|
+
quantity=row.get("quantity", 0),
|
64
|
+
cad_reference=row.get("cad_reference"),
|
65
|
+
attached_documents_reference=row.get("attached_documents_reference"),
|
66
|
+
lead_time=row.get("lead_time"),
|
67
|
+
make_or_buy=row.get("make_or_buy"),
|
68
|
+
supplier=row.get("supplier"),
|
69
|
+
manufacturer_number=row.get("manufacturer_number"),
|
70
|
+
unit_price=row.get("unit_price"),
|
71
|
+
currency=row.get("currency")
|
72
|
+
)
|
73
|
+
parts.append(part)
|
74
|
+
|
75
|
+
self.session.add_all(parts)
|
76
|
+
self.session.commit()
|
77
|
+
print(f"Imported {len(parts)} parts successfully from {file_path}")
|
78
|
+
|
79
|
+
def total_value(self):
|
80
|
+
from decimal import Decimal
|
81
|
+
all_parts = self.session.query(Part).all()
|
82
|
+
|
83
|
+
total_value = Decimal(0.0)
|
84
|
+
for part in all_parts:
|
85
|
+
total_value = Decimal(total_value) + (Decimal(part.unit_price) * part.quantity)
|
86
|
+
|
87
|
+
return total_value
|
@@ -0,0 +1,71 @@
|
|
1
|
+
from sqlalchemy import Column, Integer, String, Float, DateTime, Numeric, Enum
|
2
|
+
from sqlalchemy.orm import DeclarativeBase
|
3
|
+
from datetime import datetime
|
4
|
+
|
5
|
+
import uuid
|
6
|
+
|
7
|
+
class Base(DeclarativeBase):
|
8
|
+
pass
|
9
|
+
|
10
|
+
class Part(Base):
|
11
|
+
__tablename__ = 'parts'
|
12
|
+
|
13
|
+
id = Column(Integer, primary_key=True)
|
14
|
+
uuid = Column(String(32), unique=True, nullable=False, default=str(uuid.uuid4()))
|
15
|
+
number = Column(String(50), nullable=False)
|
16
|
+
name = Column(String(200), nullable=False)
|
17
|
+
description = Column(String(1000), default="No description")
|
18
|
+
revision = Column(String(10), default="1")
|
19
|
+
lifecycle_state = Column(String(50), default="In Work")
|
20
|
+
owner = Column(String(100), default="system")
|
21
|
+
date_created = Column(DateTime, default=datetime.utcnow)
|
22
|
+
date_modified = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
23
|
+
material = Column(String(100))
|
24
|
+
mass = Column(Float)
|
25
|
+
dimension_x = Column(Float)
|
26
|
+
dimension_y = Column(Float)
|
27
|
+
dimension_z = Column(Float)
|
28
|
+
quantity = Column(Integer, default=0)
|
29
|
+
cad_reference = Column(String(200))
|
30
|
+
attached_documents_reference = Column(String(200))
|
31
|
+
lead_time = Column(Integer)
|
32
|
+
make_or_buy = Column(Enum('make', 'buy', name='make_or_buy_enum'))
|
33
|
+
supplier = Column(String(100))
|
34
|
+
manufacturer_number = Column(String(100))
|
35
|
+
unit_price = Column(Numeric(10, 2))
|
36
|
+
currency = Column(String(3))
|
37
|
+
|
38
|
+
def __repr__(self):
|
39
|
+
return f"<Part(id={self.id}, number={self.number}, name={self.name})>"
|
40
|
+
|
41
|
+
def to_dict(self):
|
42
|
+
return {column.name: getattr(self, column.name) for column in self.__table__.columns}
|
43
|
+
|
44
|
+
|
45
|
+
class Supplier(Base):
|
46
|
+
__tablename__ = 'suppliers'
|
47
|
+
|
48
|
+
id = Column(Integer, primary_key=True)
|
49
|
+
uuid = Column(String(32), unique=True, nullable=False)
|
50
|
+
name = Column(String(200), nullable=False)
|
51
|
+
description = Column(String(1000))
|
52
|
+
date_created = Column(DateTime, default=datetime.utcnow)
|
53
|
+
date_modified = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
54
|
+
|
55
|
+
class File(Base):
|
56
|
+
__tablename__ = 'files'
|
57
|
+
|
58
|
+
id = Column(Integer, primary_key=True)
|
59
|
+
uuid = Column(String(32), unique=True, nullable=False)
|
60
|
+
name = Column(String(200), nullable=False)
|
61
|
+
description = Column(String(1000))
|
62
|
+
date_created = Column(DateTime, default=datetime.utcnow)
|
63
|
+
date_modified = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
64
|
+
|
65
|
+
class NumberRange(Base):
|
66
|
+
__tablename__ = 'number_ranges'
|
67
|
+
|
68
|
+
id = Column(Integer, primary_key=True)
|
69
|
+
name = Column(String(200), nullable=False)
|
70
|
+
description = Column(String(1000))
|
71
|
+
date_created = Column(DateTime, default=datetime.utcnow)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: OpenPartsLibrary
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Python library for creating a database of hardware components for manufacturing
|
5
|
+
Home-page: https://github.com/alekssadowski95/OpenPartsLibrary
|
6
|
+
Author: Aleksander Sadowski
|
7
|
+
Author-email: aleksander.sadowski@alsado.de
|
8
|
+
License: MIT
|
9
|
+
Classifier: Development Status :: 1 - Planning
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
License-File: LICENSE
|
14
|
+
Dynamic: author
|
15
|
+
Dynamic: author-email
|
16
|
+
Dynamic: classifier
|
17
|
+
Dynamic: home-page
|
18
|
+
Dynamic: license
|
19
|
+
Dynamic: license-file
|
20
|
+
Dynamic: summary
|
@@ -0,0 +1,8 @@
|
|
1
|
+
openpartslibrary/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
openpartslibrary/db.py,sha256=FYyQuFdJZzERniBOyWQNCuRQ_v8ZrzgXhjHUbKY1tTk,3157
|
3
|
+
openpartslibrary/models.py,sha256=yVnyV0f7hSoTG30f1UVugeLNKLkk4osDEVUU2zIUQYk,2649
|
4
|
+
openpartslibrary-0.1.0.dist-info/licenses/LICENSE,sha256=d0dlaVkR5u5bZVrTL-FmUyCoiu3o87Vc-MF1X-NYSXA,1076
|
5
|
+
openpartslibrary-0.1.0.dist-info/METADATA,sha256=5XQEXq4fscQnRrLBMQcWm0UOvh2F8kat0PeHuHuFWxY,648
|
6
|
+
openpartslibrary-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
openpartslibrary-0.1.0.dist-info/top_level.txt,sha256=-26qZ2PdH7UxxjYQmnXDViKaFDd5Mb5e_Xp__WDTdKQ,17
|
8
|
+
openpartslibrary-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Aleksander Sadowski
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
openpartslibrary
|