Metadata-Version: 2.4
Name: fastapis
Version: 0.13
Summary: Simple FastAPI/SQLAlchemy to super easy create (generic) routes, delcare db types and more.
Home-page: https://github.com/ultrafunkamsterdam/fastapis
Author: UltrafunkAmsterdam
Author-email: Me <non@yourbusiness.no>
License: ISC
Project-URL: homepage, https://www.github.com/ultrafunkamsterdam/fastapis
Project-URL: repository, https://github.com/ultrafunkamsterdam/fastapis.git
Project-URL: documentation, https://ultrafunkamsterdam.github.io/fastapis
Project-URL: issues, https://github.com/ultrafunkamsterdam/fastapis/issues
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: POSIX
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: aiomysql==0.2.0
Requires-Dist: aiosqlite==0.21.0
Requires-Dist: annotated-types==0.7.0
Requires-Dist: anyio==4.9.0
Requires-Dist: asyncpg==0.30.0
Requires-Dist: click==8.2.1
Requires-Dist: colorama==0.4.6
Requires-Dist: fastapi==0.115.12
Requires-Dist: greenlet==3.2.2
Requires-Dist: h11==0.16.0
Requires-Dist: idna==3.10
Requires-Dist: itsdangerous==2.2.0
Requires-Dist: pydantic==2.11.5
Requires-Dist: pydantic_core==2.33.2
Requires-Dist: PyMySQL==1.1.1
Requires-Dist: python-multipart==0.0.20
Requires-Dist: PyYAML==6.0.2
Requires-Dist: sniffio==1.3.1
Requires-Dist: SQLAlchemy==2.0.41
Requires-Dist: starlette==0.46.2
Requires-Dist: typing-inspection==0.4.1
Requires-Dist: typing_extensions==4.13.2
Requires-Dist: uvicorn==0.34.2
Provides-Extra: dev
Requires-Dist: black>=23.1.0; extra == "dev"
Requires-Dist: twine>=4.0.0; extra == "dev"
Requires-Dist: build; extra == "dev"
Dynamic: author
Dynamic: home-page

Faster**Apis**
====================
just a pet project for own use.

as the name implies, this let's you create FastAPI's combined with SQLAlchemy even FASTER.

the db module has a Base object which you can build db models upon.
it gives every model useful methods and fields.
eg:

```python
from fastapis import Base, Mapped 

class MyModel(Base):
    username: Mapped[str]
    password: Mapped[str]

obj = MyModel()
```

### await obj.update()   

commit to database, whether it is create of update

### obj.updated_at
gives a timestamp of last modification to the object
1748424353 

### obj.created_at
gives a timestamp of creation time
1748107770

### obj.id
by default uses uuid4
'edb45110-6520-42e6-9eaf-cd8b11df5e6f'

### obj.id_
internal id
2 

### await obj.query()
returns all objects
[<some.module.Object at 0x71418e77b970>,
 <some.module.Object at 0x71418e77a4d0>]

### obj.dict
converts to json serializable dict 
{"username": "myname",
"created_at": 124233,
"updated_at": 342423,
"id": ...
"id_": ...
}


### await obj.query(MyModel.password == "something", order_by=MyModel.username.desc(), limit=10, offset=4)
use filters to query database


### await obj.query_single()
returns a single (latest) item. also works with filters  like obj.query()


### await obj.query_with_stats()
same as query() but returns a ResultWithStatsType, containing stats like total count,
pagination etc.

- data: list of objects, just like regular query(), but this always is a list 
- count_max: 634222, 
- per_page: 16, 
- count: 16, 
- page_max: 39639, 
- has_next: True, 
- has_prev: False,
- page_index: 0, 
- range: (0, 63422)




# **Full example Fastapi and SQLAlchemy**

```python
from __future__ import annotations

from typing import Optional

from fastapi.security.oauth2 import OAuth2PasswordBearer
from sqlalchemy.testing.schema import mapped_column

from fastapis.db import Base, Mapped, relationship, ForeignKey
from fastapis.web import BaseRouter
from fastapis.web import app
from fastapis.web.types import schema_model_conf, BaseModel


# database models

class DBUser(Base):
    __tablename__ = "db_user"

    username: Mapped[str]
    password: Mapped[Optional[str]]
    token: Mapped[DBToken] = relationship(uselist=False, lazy="selectin")


class DBToken(Base):
    __tablename__ = "db_token"

    value: Mapped[str]
    user_id: Mapped[DBUser] = mapped_column(ForeignKey("db_user.id"))


# fastapi (pydantic) models

class UserRead(BaseModel):
    model_config = schema_model_conf
    username: str
    password: Optional[str] = None
    token: Optional[TokenRead] = None


class UserCreate(BaseModel):
    username: str
    password: str


class TokenRead(BaseModel):
    model_config = schema_model_conf
    value: Optional[str]


# fastapi security

security = OAuth2PasswordBearer(tokenUrl="/token")


# manual route for tokens

@app.post("/token")
async def get_token():
    return dict(access_token="123", token_type="Bearer")


# dependency

async def some_dependency():
    yield "test"


# router for users
# creates all route handlers for CRUD

user_router = BaseRouter(
    db_model=DBUser,
    model_read=UserRead,
    model_create=UserCreate,
    model_patch=UserCreate,
    security=security,
    dependencies=[some_dependency]
)

# include the above router
app.include_router(user_router, prefix="/user", tags=["user"])

# done!

if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

```

Result
-----------------------
![output api](img.png "Output API")
