python-ppa 0.1.7__py3-none-any.whl → 0.1.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-ppa
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: JPA-like ORM for Python
5
5
  Author: Pratyush Kumar
6
6
  License-Expression: MIT
@@ -14,7 +14,7 @@ Requires-Dist: idna==3.18
14
14
  Requires-Dist: pydantic==2.13.4
15
15
  Requires-Dist: pydantic_core==2.46.4
16
16
  Requires-Dist: psycopg[binary]>=3.2.0
17
- Requires-Dist: pymongo==4.17.0
17
+ Requires-Dist: pymongo==4.18.1
18
18
  Requires-Dist: python-dotenv==1.2.2
19
19
  Requires-Dist: PyYAML==6.0.3
20
20
  Requires-Dist: typing-inspection==0.4.2
@@ -118,7 +118,109 @@ framework:
118
118
  level: "DEBUG"
119
119
  ```
120
120
 
121
- ## 📖 Usage Example
121
+ ## PostgreSQL Quickstart
122
+
123
+ The `demo/` folder contains a complete local PostgreSQL verification app.
124
+
125
+ 1. Start PostgreSQL:
126
+
127
+ ```bash
128
+ cd demo
129
+ docker compose up -d
130
+ ```
131
+
132
+ 2. Run the demo from the repository root:
133
+
134
+ ```bash
135
+ ./venv/bin/python demo/main.py
136
+ ```
137
+
138
+ The demo creates a `users` table and verifies insert, convention queries, a custom SQL query, update, and delete through `ppa.postgres`.
139
+
140
+ For your own app, create `resources/settings.yml`:
141
+
142
+ ```yaml
143
+ app:
144
+ profile: ${APP_PROFILE:dev}
145
+ ```
146
+
147
+ Then create `resources/settings-dev.yml`:
148
+
149
+ ```yaml
150
+ postgresql:
151
+ host: ${POSTGRES_HOST:localhost}
152
+ port: ${POSTGRES_PORT:5432}
153
+ database: ${POSTGRES_DB_NAME:ppa_demo}
154
+ user: ${POSTGRES_USER:ppa_user}
155
+ password: ${POSTGRES_PASSWORD:ppa_password}
156
+
157
+ framework:
158
+ logging:
159
+ enabled: true
160
+ level: DEBUG
161
+ ```
162
+
163
+ You can also use a single DSN:
164
+
165
+ ```yaml
166
+ postgresql:
167
+ dsn: ${POSTGRES_DSN:postgresql://ppa_user:ppa_password@localhost:5432/ppa_demo}
168
+ ```
169
+
170
+ Create the database table before using the repository. `python-ppa` currently maps models to existing tables; it does not run migrations for you.
171
+
172
+ ```sql
173
+ CREATE TABLE IF NOT EXISTS users (
174
+ id SERIAL PRIMARY KEY,
175
+ username TEXT NOT NULL UNIQUE,
176
+ email TEXT NOT NULL,
177
+ age INTEGER NOT NULL
178
+ );
179
+ ```
180
+
181
+ Define a PostgreSQL-backed entity and repository:
182
+
183
+ ```python
184
+ from ppa.postgres import EntityModel, IRepository, query, table
185
+
186
+ @table(name="users")
187
+ class User(EntityModel):
188
+ username: str
189
+ email: str
190
+ age: int
191
+
192
+ class UserRepository(IRepository[User]):
193
+ def find_by_username(self, username: str) -> User | None: ...
194
+ def exists_by_username(self, username: str) -> bool: ...
195
+ def count_by_age(self, age: int) -> int: ...
196
+ def find_all_by_age(self, age: int) -> list[User]: ...
197
+
198
+ @query("SELECT * FROM users WHERE email = ?0 AND age >= ?1")
199
+ def find_by_email_and_min_age(self, email: str, min_age: int) -> list[User]: ...
200
+ ```
201
+
202
+ Use the repository:
203
+
204
+ ```python
205
+ from ppa.config import close_db_connection
206
+
207
+ repo = UserRepository()
208
+
209
+ user_id = repo.save(User(username="pratyush", email="pratyush@example.com", age=25))
210
+ user = repo.find_by_username("pratyush")
211
+
212
+ print(user.model_dump() if user else None)
213
+ print(repo.exists_by_username("pratyush"))
214
+ print(repo.count_by_age(25))
215
+ print(repo.find_by_email_and_min_age("pratyush@example.com", 21))
216
+
217
+ repo.update(user_id, {"age": 26})
218
+ repo.delete(user_id)
219
+
220
+ close_db_connection()
221
+ ```
222
+
223
+ ## MongoDB Usage Example
122
224
 
123
225
  Here is a quick overview of how you can configure a domain entity and generate auto-implemented interface pipelines:
124
226
 
@@ -176,26 +278,6 @@ print(f"Found User: {user.email if user else 'Not Found'}")
176
278
  close_db_connection()
177
279
  ```
178
280
 
179
- PostgreSQL repositories follow the same naming conventions with SQL-backed models:
180
-
181
- ```python
182
- from pydantic import EmailStr
183
- from ppa.postgres.interface import EntityModel, IRepository, query, table
184
-
185
- @table(name="users")
186
- class User(EntityModel):
187
- username: str
188
- email: EmailStr
189
- age: int
190
-
191
- class UserRepository(IRepository[User]):
192
- def find_by_username(self, username: str) -> User | None: ...
193
- def count_by_age(self, age: int) -> int: ...
194
-
195
- @query("SELECT * FROM users WHERE email = ?0 AND age >= ?1")
196
- def find_by_email_and_min_age(self, email: str, min_age: int) -> list[User]: ...
197
- ```
198
-
199
281
  ## 📜 License
200
282
 
201
283
  This project is open-source software licensed under the MIT License.
@@ -4,8 +4,8 @@ ppa/mongo/__init__.py,sha256=tioeX330txLUWpEyAuj8rCO6C8DISjRkNFVDs8wGe54,168
4
4
  ppa/mongo/interface.py,sha256=lKDtd1KOXIjl9gKPGP_WVoKsE54_esJadNqKIHTadcw,12684
5
5
  ppa/postgres/__init__.py,sha256=6CsIXOIIANpCcLbDjQLvsatxcMwngmJagXtPzAznqc0,222
6
6
  ppa/postgres/interface.py,sha256=1wZqP1oChgI1m23zUQ8XXg79NQDXwaKX2JB53yYe8Tg,12829
7
- python_ppa-0.1.7.dist-info/licenses/LICENSE,sha256=J2MOuVHjIUNmdrDLa3O35gQz6E_wAJh9Ke3dod_ZDWc,1071
8
- python_ppa-0.1.7.dist-info/METADATA,sha256=U-_CItCF-VENHIKzEBvPshKDXpTNtu7HltmbAJW_egM,6226
9
- python_ppa-0.1.7.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
10
- python_ppa-0.1.7.dist-info/top_level.txt,sha256=43G6at2pfqB1LsMChCc2_K8WwSSt-LoYBAYN6Sf-krk,4
11
- python_ppa-0.1.7.dist-info/RECORD,,
7
+ python_ppa-0.1.9.dist-info/licenses/LICENSE,sha256=J2MOuVHjIUNmdrDLa3O35gQz6E_wAJh9Ke3dod_ZDWc,1071
8
+ python_ppa-0.1.9.dist-info/METADATA,sha256=GyaV8mBamPm0HVJWz4dsCPNK-3pIyn4o-_PrqXf4aS8,8013
9
+ python_ppa-0.1.9.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
10
+ python_ppa-0.1.9.dist-info/top_level.txt,sha256=43G6at2pfqB1LsMChCc2_K8WwSSt-LoYBAYN6Sf-krk,4
11
+ python_ppa-0.1.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (83.0.0)
2
+ Generator: setuptools (84.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5