pax_global_header00006660000000000000000000000064145065447070014526gustar00rootroot0000000000000052 comment=ebe4d73fa9bfc2aa72ef136f15e5cf50957fd568 anysqlite-0.0.5/000077500000000000000000000000001450654470700135415ustar00rootroot00000000000000anysqlite-0.0.5/.github/000077500000000000000000000000001450654470700151015ustar00rootroot00000000000000anysqlite-0.0.5/.github/workflows/000077500000000000000000000000001450654470700171365ustar00rootroot00000000000000anysqlite-0.0.5/.github/workflows/python-package.yml000066400000000000000000000011421450654470700225710ustar00rootroot00000000000000name: Tests on: push: branches: ["master"] pull_request: branches: ["master"] jobs: tests: name: "Python ${{ matrix.python-version }}" runs-on: "ubuntu-latest" strategy: matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12" ] steps: - uses: "actions/checkout@v4" - uses: "actions/setup-python@v4" with: python-version: "${{ matrix.python-version }}" allow-prereleases: true - name: "Install dependencies" run: "pip install -r requirements.txt" - name: "Run tests" run: scripts/test anysqlite-0.0.5/.github/workflows/python-publish.yml000066400000000000000000000011341450654470700226450ustar00rootroot00000000000000name: publish on: workflow_dispatch permissions: contents: write jobs: pypi-publish: name: upload release to PyPI runs-on: ubuntu-latest env: ANYSQLITE_PYPI: ${{ secrets.ANYSQLITE_PYPI }} steps: - uses: "actions/checkout@v4" - uses: "actions/setup-python@v4" with: python-version: 3.8 - name: "Install dependencies" run: "pip install -r requirements.txt" - name: "Build" run: "hatch build" # - name: "Publish docs" # run: ./scripts/publish-docs - name: "Publish" run: "./scripts/publish" anysqlite-0.0.5/.gitignore000066400000000000000000000000401450654470700155230ustar00rootroot00000000000000venv/ __pycache__/ test.py dist/anysqlite-0.0.5/.idea/000077500000000000000000000000001450654470700145215ustar00rootroot00000000000000anysqlite-0.0.5/.idea/.gitignore000066400000000000000000000000571450654470700165130ustar00rootroot00000000000000# Default ignored files /shelf/ /workspace.xml anysqlite-0.0.5/.idea/anysqlite.iml000066400000000000000000000011551450654470700172370ustar00rootroot00000000000000 anysqlite-0.0.5/.idea/inspectionProfiles/000077500000000000000000000000001450654470700204005ustar00rootroot00000000000000anysqlite-0.0.5/.idea/inspectionProfiles/Project_Default.xml000066400000000000000000000045411450654470700242000ustar00rootroot00000000000000 anysqlite-0.0.5/.idea/inspectionProfiles/profiles_settings.xml000066400000000000000000000002561450654470700246700ustar00rootroot00000000000000 anysqlite-0.0.5/.idea/misc.xml000066400000000000000000000003061450654470700161750ustar00rootroot00000000000000 anysqlite-0.0.5/.idea/modules.xml000066400000000000000000000004161450654470700167140ustar00rootroot00000000000000 anysqlite-0.0.5/.idea/vcs.xml000066400000000000000000000002471450654470700160410ustar00rootroot00000000000000 anysqlite-0.0.5/CHANGELOG.md000066400000000000000000000000001450654470700153400ustar00rootroot00000000000000anysqlite-0.0.5/LICENSE.txt000066400000000000000000000027241450654470700153710ustar00rootroot00000000000000Copyright © 2023, Karen Petrosyan. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.anysqlite-0.0.5/README.md000066400000000000000000000013401450654470700150160ustar00rootroot00000000000000# anysqlite Anysqlite provides an `async/await` interface to the standard `sqlite3` library and supports both `trio` and `asyncio` backends using the power of [Anyio](https://github.com/agronholm/anyio). [![PyPI - Version](https://img.shields.io/pypi/v/anysqlite.svg)](https://pypi.org/project/anysqlite) [![PyPI - Python Version](https://img.shields.io/pyp1i/pyversions/anysqlite.svg)](https://pypi.org/project/anysqlite) ----- ## Installation ```console pip install anysqlite ``` ## Basic usage ``` python >>> import anysqlite >>> >>> conn = await anysqlite.connect(":memory:") >>> cursor = await conn.execute("SELECT DATETIME()") >>> >>> response = await cursor.fetchone() >>> print(response) [('2023-10-02 13:42:42',)] ```anysqlite-0.0.5/anysqlite/000077500000000000000000000000001450654470700155525ustar00rootroot00000000000000anysqlite-0.0.5/anysqlite/__init__.py000066400000000000000000000014241450654470700176640ustar00rootroot00000000000000from sqlite3 import ( # noqa: F401 DatabaseError, DataError, Error, IntegrityError, InterfaceError, InternalError, NotSupportedError, OperationalError, ProgrammingError, Row, Warning, apilevel, paramstyle, sqlite_version, sqlite_version_info, threadsafety, ) from ._core import Connection, Cursor, connect # noqa: F401 __all__ = [ "Connection", "Cursor", "connect", "DatabaseError", "DataError", "Error", "IntegrityError", "InterfaceError", "InternalError", "NotSupportedError", "OperationalError", "ProgrammingError", "Row", "Warning", "apilevel", "paramstyle", "sqlite_version", "sqlite_version_info", "threadsafety", ] __version__ = "0.0.5" anysqlite-0.0.5/anysqlite/_core.py000066400000000000000000000104201450654470700172100ustar00rootroot00000000000000import sqlite3 import typing as tp from functools import partial from pathlib import Path from anyio import CapacityLimiter, to_thread class Connection: def __init__(self, _real_connection: sqlite3.Connection) -> None: self._real_connection = _real_connection self._limiter = CapacityLimiter(1) async def __aenter__(self) -> "Connection": return self async def __aexit__(self, *args: tp.Any, **kwargs: tp.Any) -> None: return await self.close() async def close(self) -> None: return await to_thread.run_sync( self._real_connection.close, limiter=self._limiter ) async def commit(self) -> None: return await to_thread.run_sync( self._real_connection.commit, limiter=self._limiter ) async def rollback(self) -> None: return await to_thread.run_sync( self._real_connection.rollback, limiter=self._limiter ) async def cursor(self) -> "Cursor": real_cursor = await to_thread.run_sync( self._real_connection.cursor, limiter=self._limiter ) return Cursor(real_cursor, self._limiter) async def execute(self, sql: str, parameters: tp.Iterable[tp.Any] = ()) -> "Cursor": real_cursor = await to_thread.run_sync( self._real_connection.execute, sql, parameters, limiter=self._limiter ) return Cursor(real_cursor, self._limiter) async def executemany( self, sql: str, seq_of_parameters: tp.Iterable[tp.Iterable[tp.Any]] ) -> "Cursor": real_cursor = await to_thread.run_sync( self._real_connection.executemany, sql, seq_of_parameters, limiter=self._limiter, ) return Cursor(real_cursor, self._limiter) async def executescript(self, sql_script: str) -> "Cursor": real_cursor = await to_thread.run_sync( self._real_connection.executescript, sql_script, limiter=self._limiter ) return Cursor(real_cursor, self._limiter) class Cursor: def __init__(self, real_cursor: sqlite3.Cursor, limiter: CapacityLimiter) -> None: self._real_cursor = real_cursor self._limiter = limiter @property def description( self, ) -> tp.Union[ tp.Tuple[tp.Tuple[str, None, None, None, None, None, None], ...], tp.Any ]: return self._real_cursor.description @property def rowcount(self) -> int: return self._real_cursor.rowcount @property def arraysize(self) -> int: return self._real_cursor.arraysize async def close(self) -> None: await to_thread.run_sync(self._real_cursor.close, limiter=self._limiter) async def execute(self, sql: str, parameters: tp.Iterable[tp.Any] = ()) -> "Cursor": real_cursor = await to_thread.run_sync( self._real_cursor.execute, sql, parameters, limiter=self._limiter ) return Cursor(real_cursor, self._limiter) async def executemany( self, sql: str, seq_of_parameters: tp.Iterable[tp.Iterable[tp.Any]] ) -> "Cursor": real_cursor = await to_thread.run_sync( self._real_cursor.executemany, sql, seq_of_parameters, limiter=self._limiter ) return Cursor(real_cursor, self._limiter) async def executescript(self, sql_script: str) -> "Cursor": real_cursor = await to_thread.run_sync( self._real_cursor.executescript, sql_script, limiter=self._limiter ) return Cursor(real_cursor, self._limiter) async def fetchone(self) -> tp.Any: return await to_thread.run_sync( self._real_cursor.fetchone, limiter=self._limiter ) async def fetchmany(self, size: tp.Union[int, None] = 1) -> tp.Any: return await to_thread.run_sync( self._real_cursor.fetchmany, size, limiter=self._limiter ) async def fetchall(self) -> tp.Any: return await to_thread.run_sync( self._real_cursor.fetchall, limiter=self._limiter ) async def connect( database: tp.Union[str, bytes, Path], **kwargs: tp.Any ) -> "Connection": kwargs["check_same_thread"] = False real_connection = await to_thread.run_sync( partial(sqlite3.connect, database, **kwargs) ) return Connection(real_connection) anysqlite-0.0.5/anysqlite/py.typed000066400000000000000000000000001450654470700172370ustar00rootroot00000000000000anysqlite-0.0.5/pyproject.toml000066400000000000000000000035661450654470700164670ustar00rootroot00000000000000[build-system] requires = ["hatchling", "hatch-fancy-pypi-readme"] build-backend = "hatchling.build" [project] name = "anysqlite" dynamic = ["version"] description = '' readme = "README.md" license = "BSD-3-Clause" requires-python = ">=3.8" keywords = [] authors = [ { name = "Karen Petrosyan", email = "kar.petrosyanpy@gmail.com" }, ] classifiers = [ "Development Status :: 4 - Beta", "Programming Language :: Python", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] dependencies = [ "anyio>3.4.0" ] [project.urls] Issues = "https://github.com/karosis88/anysqlite/issues" Source = "https://github.com/karosis88/anysqlite" [tool.hatch.version] path = "anysqlite/__init__.py" [tool.hatch.build.targets.sdist] include = [ "/anysqlite", "/CHANGELOG.md", "/README.md", ] [tool.hatch.metadata.hooks.fancy-pypi-readme] content-type = "text/markdown" [[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]] path = "README.md" [[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]] path = "CHANGELOG.md" [tool.mypy] strict = true show_error_codes = true warn_unused_ignores = false [[tool.mypy.overrides]] module = "tests.*" disallow_untyped_defs = false check_untyped_defs = true [tool.pytest.ini_options] addopts = ["-rxXs", "--strict-config", "--strict-markers"] filterwarnings = [] [tool.coverage.run] omit = [ "venv/*", ] include = ["anysqlite/*", "tests/*"] [tool.coverage.report] exclude_also = [ '__repr__', 'raise NotImplementedError()' ] [tool.ruff] line-length = 120 select = [ "E", "F", "W", "I" ] [tool.ruff.isort] combine-as-imports = trueanysqlite-0.0.5/requirements.txt000066400000000000000000000001241450654470700170220ustar00rootroot00000000000000-e . black==23.9.1 mypy==1.5.1 pytest==7.4.2 ruff==0.0.291 trio>0.20.0 hatch==1.7.0anysqlite-0.0.5/scripts/000077500000000000000000000000001450654470700152305ustar00rootroot00000000000000anysqlite-0.0.5/scripts/check000077500000000000000000000001401450654470700162260ustar00rootroot00000000000000#! /bin/bash -ex black --check --diff tests anysqlite ruff tests anysqlite mypy tests anysqliteanysqlite-0.0.5/scripts/install000077500000000000000000000002051450654470700166210ustar00rootroot00000000000000#! /bin/bash -x rm -rf venv python -m venv venv source venv/bin/activate pip install --upgrade pip pip install -r requirements.txtanysqlite-0.0.5/scripts/lint000077500000000000000000000001031450654470700161160ustar00rootroot00000000000000#! /bin/bash -ex black anysqlite tests ruff --fix anysqlite tests anysqlite-0.0.5/scripts/publish000077500000000000000000000001001450654470700166130ustar00rootroot00000000000000#! /bin/bash -ex hatch publish -u __token__ -a $ANYSQLITE_PYPI anysqlite-0.0.5/scripts/publish-docs000077500000000000000000000000531450654470700175500ustar00rootroot00000000000000#! /bin/bash -ex mkdocs gh-deploy --force anysqlite-0.0.5/scripts/test000077500000000000000000000000641450654470700161350ustar00rootroot00000000000000#! /bin/bash -e set -x ./scripts/check pytest testsanysqlite-0.0.5/tests/000077500000000000000000000000001450654470700147035ustar00rootroot00000000000000anysqlite-0.0.5/tests/__init__.py000066400000000000000000000000001450654470700170020ustar00rootroot00000000000000anysqlite-0.0.5/tests/test_smoke.py000066400000000000000000000010201450654470700174230ustar00rootroot00000000000000import pytest import anysqlite @pytest.mark.anyio async def test_anysqlite(): db = await anysqlite.connect(":memory:") try: cursor = await db.cursor() await cursor.execute("CREATE TABLE anysqlite_test(version TEXT)") await cursor.execute( "INSERT INTO anysqlite_test VALUES(?)", [anysqlite.__version__] ) await cursor.execute("SELECT * FROM anysqlite_test") assert (anysqlite.__version__,) == await cursor.fetchone() finally: await db.close() anysqlite-0.0.5/typetest.py000066400000000000000000000010731450654470700157750ustar00rootroot00000000000000import typing as tp import sqlite3 P = tp.ParamSpec("P") T = tp.TypeVar("T") RT = tp.TypeVar("RT") def copy_sig(_: tp.Callable[P, T], returns: tp.Callable[..., RT]) -> tp.Callable[[tp.Callable[..., tp.Any]], tp.Callable[P, RT]]: def decorator(fnc: tp.Callable[..., tp.Any]) -> tp.Callable[P, RT]: def inner(*args, **kwargs): return fnc(*args, **kwargs) return inner return decorator @copy_sig(sqlite3.connect, int.__new__) async def connect(*args, **kwargs): ... tp.reveal_type(connect) a = connect() tp.reveal_type(a)