Skip to main content

SQLPage

Python library to easily add pagination on top of DB queries. Supports SQLAlchemy and SQLModel ORMs. This returns a base64 encoded string that can be used to paginate through the results.

Usage

Install the latest version from PyPi

pip install sqlpage

Now configure your ORM and then simply call the paginate function to get the paginated results.

result: PageData = paginate(session, query, page_size=page_size)

Configuring with ORMs

Before using the paginate function, you need to configure the ORM. As SQLAlchemy and SQLModel uses different ORMs, you need to configure them separately. This is a one-time setup and you would have already taken this while configuring the ORM when creating the DB models.

SQLAlchemy

Create your table model

Base = declarative_base()

class User(Base):
    __tablename__ = 'user'

    id = Column(Integer, primary_key=True)
    username = Column(String)
    email = Column(String)

Then create a DB session and call

engine = create_engine(f"sqlite:///{DATABASE_NAME}", echo=False)
Base.metadata.create_all(engine)

SessionSqlAlchemy = sessionmaker(bind=engine)
session = SessionSqlAlchemy()

query = session.query(TestTable)

result: PageData = paginate(session, query, page_size=100)

SQLModel

Create your table model

class User(SQLModel, table=True):
    __tablename__ = 'user'

    id: int = Field(primary_key=True)
    username: str = Field(default=None)
    email: str = Field(default=None)

Then create a DB session and call

engine = create_engine(f"sqlite:///{DATABASE_NAME}", echo=False)
Base.metadata.create_all(engine)

with Session(engine) as session:

    query = session.query(TestTable)

    result: PageData = paginate(session, query, page_size=100)

Contributing

Feel free to open an issues under the Issues tab. Contributions are welcome and appreciated.

Metadata

Release files for sqlpage 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlpage 0.1.0
File Size Uploaded Provenance Actions
sqlpage-0.1.0.tar.gz 4.9 kB Without provenance Details for sqlpage-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqlpage 0.1.0
File Interpreter ABI Platform Actions
sqlpage-0.1.0-py3-none-any.whl Python 3 none any Details for sqlpage-0.1.0-py3-none-any.whl

Total release size: 9.6 kB

Release files / sqlpage-0.1.0.tar.gz

Download URL sqlpage-0.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
21d980c50ed1272f3118fa94d45c29a8940b58fd5d94ba0a7debc433d9704adb
BLAKE2b-256 checksum
How to use checksums
2c0a4ad98bd235439ecadd45c3047c0b1f071a75ece97d9de6d799d268518121
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.7

Release files / sqlpage-0.1.0-py3-none-any.whl

Download URL sqlpage-0.1.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a74324489088569152b43ba1d0361b7ab6a5eb2f00bf42010fea1e526bea1cd4
BLAKE2b-256 checksum
How to use checksums
45afdb5610d6adeac028624eec16546958518aaa9c14588672a034ec3ab9a264
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.7

Security for sqlpage 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page