Skip to content

Commit 8c6dc3e

Browse files
committed
Refactor to pyproject.toml for modern Python packaging
Migrated project to modern Python packaging standards using pyproject.toml: - Removed legacy setup.py and __version__.py files - Added pyproject.toml with PEP 621-compliant project metadata - Moved dependencies to pyproject.toml (typing-extensions) - Updated build.bat to use python -m build instead of setup.py - Removed redundant requirements.txt - Fixed import ordering in sessions.py This modernizes the packaging system, improves security by eliminating executable setup.py, and aligns with current PyPA recommendations for Python projects. Version is now managed directly in pyproject.toml following PEP 621 specifications.
1 parent 7cddd5b commit 8c6dc3e

File tree

6 files changed

+119
-135
lines changed

6 files changed

+119
-135
lines changed

async_tls_client/__version__.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

async_tls_client/sessions.py

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
from .cffi import request, freeMemory, destroySession
2-
from .cookies import cookiejar_from_dict, merge_cookies, extract_cookies_to_jar
3-
from .exceptions import TLSClientExeption
4-
from .response import build_response, Response
5-
from .settings import ClientIdentifiers
6-
from .structures import CaseInsensitiveDict
7-
from .__version__ import __version__
8-
9-
from typing import Any, Dict, List, Optional, Union
10-
from json import dumps, loads
11-
import urllib.parse
1+
import asyncio
122
import base64
133
import ctypes
4+
import urllib.parse
145
import uuid
15-
import asyncio
6+
from json import dumps, loads
7+
from typing import Any, Dict, List, Optional, Union
8+
9+
from .cffi import destroySession, freeMemory, request
10+
from .cookies import cookiejar_from_dict, extract_cookies_to_jar, merge_cookies
11+
from .exceptions import TLSClientExeption
12+
from .response import Response, build_response
13+
from .settings import ClientIdentifiers
14+
from .structures import CaseInsensitiveDict
1615

1716

1817
class AsyncSession:
@@ -41,27 +40,27 @@ class AsyncSession:
4140
"""
4241

4342
def __init__(
44-
self,
45-
client_identifier: ClientIdentifiers = "chrome_120",
46-
ja3_string: Optional[str] = None,
47-
h2_settings: Optional[Dict[str, int]] = None,
48-
h2_settings_order: Optional[List[str]] = None,
49-
supported_signature_algorithms: Optional[List[str]] = None,
50-
supported_delegated_credentials_algorithms: Optional[List[str]] = None,
51-
supported_versions: Optional[List[str]] = None,
52-
key_share_curves: Optional[List[str]] = None,
53-
cert_compression_algo: str = None,
54-
additional_decode: str = None,
55-
pseudo_header_order: Optional[List[str]] = None,
56-
connection_flow: Optional[int] = None,
57-
priority_frames: Optional[list] = None,
58-
header_order: Optional[List[str]] = None,
59-
header_priority: Optional[List[str]] = None,
60-
random_tls_extension_order: Optional[bool] = False,
61-
force_http1: Optional[bool] = False,
62-
catch_panics: Optional[bool] = False,
63-
debug: Optional[bool] = False,
64-
certificate_pinning: Optional[Dict[str, List[str]]] = None,
43+
self,
44+
client_identifier: ClientIdentifiers = "chrome_120",
45+
ja3_string: Optional[str] = None,
46+
h2_settings: Optional[Dict[str, int]] = None,
47+
h2_settings_order: Optional[List[str]] = None,
48+
supported_signature_algorithms: Optional[List[str]] = None,
49+
supported_delegated_credentials_algorithms: Optional[List[str]] = None,
50+
supported_versions: Optional[List[str]] = None,
51+
key_share_curves: Optional[List[str]] = None,
52+
cert_compression_algo: str = None,
53+
additional_decode: str = None,
54+
pseudo_header_order: Optional[List[str]] = None,
55+
connection_flow: Optional[int] = None,
56+
priority_frames: Optional[list] = None,
57+
header_order: Optional[List[str]] = None,
58+
header_priority: Optional[List[str]] = None,
59+
random_tls_extension_order: Optional[bool] = False,
60+
force_http1: Optional[bool] = False,
61+
catch_panics: Optional[bool] = False,
62+
debug: Optional[bool] = False,
63+
certificate_pinning: Optional[Dict[str, List[str]]] = None,
6564
) -> None:
6665
"""
6766
Initializes the AsyncSession with various HTTP and TLS parameters.
@@ -307,18 +306,18 @@ async def close(self) -> str:
307306
return destroy_session_response_string
308307

309308
async def execute_request(
310-
self,
311-
method: str,
312-
url: str,
313-
params: Optional[dict] = None,
314-
data: Optional[Union[str, dict]] = None,
315-
headers: Optional[dict] = None,
316-
cookies: Optional[dict] = None,
317-
json: Optional[dict] = None,
318-
allow_redirects: Optional[bool] = False,
319-
insecure_skip_verify: Optional[bool] = False,
320-
timeout_seconds: Optional[int] = None,
321-
proxy: Optional[dict] = None
309+
self,
310+
method: str,
311+
url: str,
312+
params: Optional[dict] = None,
313+
data: Optional[Union[str, dict]] = None,
314+
headers: Optional[dict] = None,
315+
cookies: Optional[dict] = None,
316+
json: Optional[dict] = None,
317+
allow_redirects: Optional[bool] = False,
318+
insecure_skip_verify: Optional[bool] = False,
319+
timeout_seconds: Optional[int] = None,
320+
proxy: Optional[dict] = None
322321
) -> Response:
323322
"""
324323
Executes an HTTP request using the Go-based TLS client in a separate thread.
@@ -358,6 +357,7 @@ async def execute_request(
358357
Raises:
359358
TLSClientExeption: If the underlying Go client returns a status code of 0 (error).
360359
"""
360+
361361
def build_payload():
362362
# Prepare URL - add params to url
363363
final_url = url
@@ -531,11 +531,11 @@ async def head(self, url: str, **kwargs: Any) -> Response:
531531
return await self.execute_request(method="HEAD", url=url, **kwargs)
532532

533533
async def post(
534-
self,
535-
url: str,
536-
data: Optional[Union[str, dict]] = None,
537-
json: Optional[dict] = None,
538-
**kwargs: Any
534+
self,
535+
url: str,
536+
data: Optional[Union[str, dict]] = None,
537+
json: Optional[dict] = None,
538+
**kwargs: Any
539539
) -> Response:
540540
"""
541541
Sends an asynchronous POST request.
@@ -556,11 +556,11 @@ async def post(
556556
return await self.execute_request(method="POST", url=url, data=data, json=json, **kwargs)
557557

558558
async def put(
559-
self,
560-
url: str,
561-
data: Optional[Union[str, dict]] = None,
562-
json: Optional[dict] = None,
563-
**kwargs: Any
559+
self,
560+
url: str,
561+
data: Optional[Union[str, dict]] = None,
562+
json: Optional[dict] = None,
563+
**kwargs: Any
564564
) -> Response:
565565
"""
566566
Sends an asynchronous PUT request.
@@ -581,11 +581,11 @@ async def put(
581581
return await self.execute_request(method="PUT", url=url, data=data, json=json, **kwargs)
582582

583583
async def patch(
584-
self,
585-
url: str,
586-
data: Optional[Union[str, dict]] = None,
587-
json: Optional[dict] = None,
588-
**kwargs: Any
584+
self,
585+
url: str,
586+
data: Optional[Union[str, dict]] = None,
587+
json: Optional[dict] = None,
588+
**kwargs: Any
589589
) -> Response:
590590
"""
591591
Sends an asynchronous PATCH request.

pyproject.toml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[build-system]
2+
requires = ["setuptools>=65.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "async_tls_client"
7+
version = "1.1"
8+
description = "Asyncio-first TLS client with advanced fingerprinting capabilities"
9+
readme = "README.md"
10+
authors = [
11+
{ name = "Diprog", email = "your@email.com" },
12+
{ name = "Florian Zager", email = "florian.zager@gmail.com" }
13+
]
14+
license = { text = "MIT" }
15+
keywords = ["tls", "asyncio", "http-client", "ja3", "fingerprinting", "http2"]
16+
classifiers = [
17+
"Environment :: Web Environment",
18+
"Intended Audience :: Developers",
19+
"License :: OSI Approved :: MIT License",
20+
"Natural Language :: English",
21+
"Operating System :: OS Independent",
22+
"Programming Language :: Python :: 3",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Programming Language :: Python :: 3.11",
26+
"Programming Language :: Python :: 3.12",
27+
"Topic :: Internet :: WWW/HTTP",
28+
"Topic :: Software Development :: Libraries",
29+
]
30+
requires-python = ">=3.9"
31+
dependencies = [
32+
"typing-extensions>=4.0",
33+
]
34+
35+
[project.urls]
36+
Homepage = "https://github.com/diprog/python-tls-client-async"
37+
Documentation = "https://github.com/diprog/python-tls-client-async#readme"
38+
Original = "https://github.com/FlorianREGAZ/Python-Tls-Client"
39+
Issues = "https://github.com/diprog/python-tls-client-async/issues"
40+
Changelog = "https://github.com/diprog/python-tls-client-async/releases"
41+
42+
[tool.setuptools]
43+
include-package-data = true
44+
45+
[tool.setuptools.package-data]
46+
async_tls_client = [
47+
"dependencies/*.dll",
48+
"dependencies/*.dylib",
49+
"dependencies/*.so",
50+
]
51+
52+
[tool.setuptools.packages.find]
53+
where = ["."]
54+
include = ["async_tls_client*"]
55+
exclude = ["tests*", "examples*", "scripts*"]

requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/build.bat

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
python setup.py sdist bdist_wheel
2-
twine upload dist/* --verbose
1+
@echo off
2+
python -m pip install --upgrade build twine
3+
python -m build --sdist --wheel --outdir dist/
4+
twine upload dist/*

setup.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)