ocy 1.0.0__tar.gz

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.
ocy-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: ocy
3
+ Version: 1.0.0
4
+ Summary: Lightweight OCR for developer screenshots — extract text from code images, terminals, and IDE windows
5
+ Author: Samin Yeasar
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/solez-ai/ocy
8
+ Project-URL: Repository, https://github.com/solez-ai/ocy
9
+ Project-URL: Issues, https://github.com/solez-ai/ocy/issues
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: httpx>=0.24.0
23
+
24
+ ![OCY](https://raw.githubusercontent.com/solez-ai/ocy/main/public/logo.png)
25
+
26
+ # OCY - Python OCR SDK
27
+
28
+ Lightweight OCR for developer screenshots — extract text from code images, terminals, and IDE windows with one line of code.
29
+
30
+ **Made by Samin Yeasar • [github.com/solez-ai](https://github.com/solez-ai) • [x.com/Solez_None](https://x.com/Solez_None)**
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install ocy
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ### 1. Set your API URL
41
+
42
+ First, set the API URL. You can use a self-hosted instance or a public one:
43
+
44
+ ```python
45
+ import ocy
46
+
47
+ # Set your API URL (required)
48
+ ocy.set_api_url("https://your-api.vercel.app")
49
+ ```
50
+
51
+ ### 2. Extract text from a URL
52
+
53
+ ```python
54
+ result = ocy.extract_text("https://example.com/screenshot.png")
55
+ print(result["text"])
56
+ print(f"Confidence: {result['confidence']:.1%}")
57
+ ```
58
+
59
+ ### 3. Extract text from a local file
60
+
61
+ ```python
62
+ result = ocy.extract_text("./myScreenshot.png")
63
+ print(result["text"])
64
+ ```
65
+
66
+ ### 4. Async usage
67
+
68
+ ```python
69
+ import asyncio
70
+ import ocy
71
+
72
+ async def main():
73
+ result = await ocy.extract_text_async("https://example.com/code.png")
74
+ print(result["text"])
75
+
76
+ asyncio.run(main())
77
+ ```
78
+
79
+ ### 5. Use an API key
80
+
81
+ ```python
82
+ import ocy
83
+
84
+ # Option 1: Per-request key
85
+ result = ocy.extract_text("https://example.com/screenshot.png", api_key="your-key")
86
+
87
+ # Option 2: Set global key
88
+ ocy.set_api_key("your-key")
89
+ result = ocy.extract_text("https://example.com/screenshot.png")
90
+ ```
91
+
92
+ ## Response Format
93
+
94
+ ```python
95
+ {
96
+ "text": "extracted text from image...",
97
+ "confidence": 0.95, # 0.0 to 1.0
98
+ "latency_ms": 150, # processing time in milliseconds
99
+ "model": "ocy-v1-int8", # model identifier
100
+ "chars_detected": 42 # number of characters detected
101
+ }
102
+ ```
103
+
104
+ ## API Reference
105
+
106
+ | Function | Description |
107
+ |----------|-------------|
108
+ | `extract_text(img, api_key=None)` | Extract text synchronously |
109
+ | `extract_text_async(img, api_key=None)` | Extract text asynchronously |
110
+ | `set_api_url(url)` | Set custom API endpoint |
111
+ | `set_api_key(key)` | Set global API key |
112
+
113
+ ## License
114
+
115
+ MIT License - See [LICENSE](https://github.com/solez-ai/ocy/blob/main/LICENSE) for details.
ocy-1.0.0/README.md ADDED
@@ -0,0 +1,92 @@
1
+ ![OCY](https://raw.githubusercontent.com/solez-ai/ocy/main/public/logo.png)
2
+
3
+ # OCY - Python OCR SDK
4
+
5
+ Lightweight OCR for developer screenshots — extract text from code images, terminals, and IDE windows with one line of code.
6
+
7
+ **Made by Samin Yeasar • [github.com/solez-ai](https://github.com/solez-ai) • [x.com/Solez_None](https://x.com/Solez_None)**
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pip install ocy
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ### 1. Set your API URL
18
+
19
+ First, set the API URL. You can use a self-hosted instance or a public one:
20
+
21
+ ```python
22
+ import ocy
23
+
24
+ # Set your API URL (required)
25
+ ocy.set_api_url("https://your-api.vercel.app")
26
+ ```
27
+
28
+ ### 2. Extract text from a URL
29
+
30
+ ```python
31
+ result = ocy.extract_text("https://example.com/screenshot.png")
32
+ print(result["text"])
33
+ print(f"Confidence: {result['confidence']:.1%}")
34
+ ```
35
+
36
+ ### 3. Extract text from a local file
37
+
38
+ ```python
39
+ result = ocy.extract_text("./myScreenshot.png")
40
+ print(result["text"])
41
+ ```
42
+
43
+ ### 4. Async usage
44
+
45
+ ```python
46
+ import asyncio
47
+ import ocy
48
+
49
+ async def main():
50
+ result = await ocy.extract_text_async("https://example.com/code.png")
51
+ print(result["text"])
52
+
53
+ asyncio.run(main())
54
+ ```
55
+
56
+ ### 5. Use an API key
57
+
58
+ ```python
59
+ import ocy
60
+
61
+ # Option 1: Per-request key
62
+ result = ocy.extract_text("https://example.com/screenshot.png", api_key="your-key")
63
+
64
+ # Option 2: Set global key
65
+ ocy.set_api_key("your-key")
66
+ result = ocy.extract_text("https://example.com/screenshot.png")
67
+ ```
68
+
69
+ ## Response Format
70
+
71
+ ```python
72
+ {
73
+ "text": "extracted text from image...",
74
+ "confidence": 0.95, # 0.0 to 1.0
75
+ "latency_ms": 150, # processing time in milliseconds
76
+ "model": "ocy-v1-int8", # model identifier
77
+ "chars_detected": 42 # number of characters detected
78
+ }
79
+ ```
80
+
81
+ ## API Reference
82
+
83
+ | Function | Description |
84
+ |----------|-------------|
85
+ | `extract_text(img, api_key=None)` | Extract text synchronously |
86
+ | `extract_text_async(img, api_key=None)` | Extract text asynchronously |
87
+ | `set_api_url(url)` | Set custom API endpoint |
88
+ | `set_api_key(key)` | Set global API key |
89
+
90
+ ## License
91
+
92
+ MIT License - See [LICENSE](https://github.com/solez-ai/ocy/blob/main/LICENSE) for details.
@@ -0,0 +1,161 @@
1
+ """
2
+ OCY - Lightweight OCR SDK for Python
3
+ Extract text from developer screenshots with one line of code.
4
+ """
5
+
6
+ import asyncio
7
+ import os
8
+ import httpx
9
+ from typing import Union, Optional
10
+
11
+ __version__ = "1.0.0"
12
+
13
+ # API configuration - must be set by user
14
+ _api_url: Optional[str] = None
15
+ _api_key: Optional[str] = None
16
+
17
+
18
+ def set_api_url(url: str) -> None:
19
+ """Set a custom API URL for self-hosted instances."""
20
+ global _api_url
21
+ _api_url = url
22
+
23
+
24
+ def set_api_key(key: str) -> None:
25
+ """Set the API key for authenticated requests."""
26
+ global _api_key
27
+ _api_key = key
28
+
29
+
30
+ def _upload_to_0x0(file_path: str) -> str:
31
+ """Upload a file to 0x0.st and return the URL."""
32
+ with open(file_path, 'rb') as f:
33
+ files = {'file': (os.path.basename(file_path), f, 'application/octet-stream')}
34
+ response = httpx.post('https://0x0.st', files=files)
35
+ response.raise_for_status()
36
+ return response.text.strip()
37
+
38
+
39
+ def _upload_bytes_to_0x0(data: bytes, filename: str = 'image.png') -> str:
40
+ """Upload raw bytes to 0x0.st and return the URL."""
41
+ files = {'file': (filename, data, 'application/octet-stream')}
42
+ response = httpx.post('https://0x0.st', files=files)
43
+ response.raise_for_status()
44
+ return response.text.strip()
45
+
46
+
47
+ def extract_text(
48
+ img: Union[str, bytes],
49
+ api_key: Optional[str] = None
50
+ ) -> dict:
51
+ """
52
+ Extract text from an image.
53
+
54
+ Args:
55
+ img: Image can be a URL string, local file path, or raw bytes
56
+ api_key: Optional API key for authenticated requests
57
+
58
+ Returns:
59
+ dict with keys: text, confidence, latency_ms, model, chars_detected
60
+
61
+ Example:
62
+ >>> import ocy
63
+ >>> result = ocy.extract_text("https://example.com/screenshot.png")
64
+ >>> print(result['text'])
65
+ """
66
+ global _api_key
67
+
68
+ if not _api_url:
69
+ raise ValueError("API URL not set. Call set_api_url() first or set OCY_API_URL environment variable.")
70
+
71
+ # Determine image URL
72
+ image_url = img
73
+
74
+ if isinstance(img, str):
75
+ # Check if it's a local file path
76
+ if not img.startswith(('http://', 'https://')):
77
+ if os.path.isfile(img):
78
+ image_url = _upload_to_0x0(img)
79
+ else:
80
+ raise ValueError(f"Invalid URL or file path: {img}")
81
+ elif isinstance(img, bytes):
82
+ image_url = _upload_bytes_to_0x0(img)
83
+ else:
84
+ raise TypeError("img must be a URL string, file path, or bytes")
85
+
86
+ # Build request
87
+ headers = {"Content-Type": "application/json"}
88
+ if api_key:
89
+ headers["x-api-key"] = api_key
90
+ elif _api_key:
91
+ headers["x-api-key"] = _api_key
92
+
93
+ # Make request
94
+ with httpx.Client(timeout=30.0) as client:
95
+ response = client.post(
96
+ f"{_api_url}/api/extract",
97
+ json={"image_url": image_url},
98
+ headers=headers
99
+ )
100
+ response.raise_for_status()
101
+ return response.json()
102
+
103
+
104
+ async def extract_text_async(
105
+ img: Union[str, bytes],
106
+ api_key: Optional[str] = None
107
+ ) -> dict:
108
+ """
109
+ Async version of extract_text for use with asyncio.
110
+
111
+ Args:
112
+ img: Image can be a URL string, local file path, or raw bytes
113
+ api_key: Optional API key for authenticated requests
114
+
115
+ Returns:
116
+ dict with keys: text, confidence, latency_ms, model, chars_detected
117
+ """
118
+ global _api_key
119
+
120
+ if not _api_url:
121
+ raise ValueError("API URL not set. Call set_api_url() first or set OCY_API_URL environment variable.")
122
+
123
+ # Determine image URL
124
+ image_url = img
125
+
126
+ if isinstance(img, str):
127
+ if not img.startswith(('http://', 'https://')):
128
+ if os.path.isfile(img):
129
+ async with httpx.AsyncClient() as client:
130
+ with open(img, 'rb') as f:
131
+ files = {'file': (os.path.basename(img), f, 'application/octet-stream')}
132
+ response = await client.post('https://0x0.st', files=files)
133
+ response.raise_for_status()
134
+ image_url = response.text.strip()
135
+ else:
136
+ raise ValueError(f"Invalid URL or file path: {img}")
137
+ elif isinstance(img, bytes):
138
+ async with httpx.AsyncClient() as client:
139
+ files = {'file': ('image.png', img, 'application/octet-stream')}
140
+ response = await client.post('https://0x0.st', files=files)
141
+ response.raise_for_status()
142
+ image_url = response.text.strip()
143
+ else:
144
+ raise TypeError("img must be a URL string, file path, or bytes")
145
+
146
+ # Build request
147
+ headers = {"Content-Type": "application/json"}
148
+ if api_key:
149
+ headers["x-api-key"] = api_key
150
+ elif _api_key:
151
+ headers["x-api-key"] = _api_key
152
+
153
+ # Make async request
154
+ async with httpx.AsyncClient(timeout=30.0) as client:
155
+ response = await client.post(
156
+ f"{_api_url}/api/extract",
157
+ json={"image_url": image_url},
158
+ headers=headers
159
+ )
160
+ response.raise_for_status()
161
+ return response.json()
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: ocy
3
+ Version: 1.0.0
4
+ Summary: Lightweight OCR for developer screenshots — extract text from code images, terminals, and IDE windows
5
+ Author: Samin Yeasar
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/solez-ai/ocy
8
+ Project-URL: Repository, https://github.com/solez-ai/ocy
9
+ Project-URL: Issues, https://github.com/solez-ai/ocy/issues
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
20
+ Requires-Python: >=3.8
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: httpx>=0.24.0
23
+
24
+ ![OCY](https://raw.githubusercontent.com/solez-ai/ocy/main/public/logo.png)
25
+
26
+ # OCY - Python OCR SDK
27
+
28
+ Lightweight OCR for developer screenshots — extract text from code images, terminals, and IDE windows with one line of code.
29
+
30
+ **Made by Samin Yeasar • [github.com/solez-ai](https://github.com/solez-ai) • [x.com/Solez_None](https://x.com/Solez_None)**
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install ocy
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ### 1. Set your API URL
41
+
42
+ First, set the API URL. You can use a self-hosted instance or a public one:
43
+
44
+ ```python
45
+ import ocy
46
+
47
+ # Set your API URL (required)
48
+ ocy.set_api_url("https://your-api.vercel.app")
49
+ ```
50
+
51
+ ### 2. Extract text from a URL
52
+
53
+ ```python
54
+ result = ocy.extract_text("https://example.com/screenshot.png")
55
+ print(result["text"])
56
+ print(f"Confidence: {result['confidence']:.1%}")
57
+ ```
58
+
59
+ ### 3. Extract text from a local file
60
+
61
+ ```python
62
+ result = ocy.extract_text("./myScreenshot.png")
63
+ print(result["text"])
64
+ ```
65
+
66
+ ### 4. Async usage
67
+
68
+ ```python
69
+ import asyncio
70
+ import ocy
71
+
72
+ async def main():
73
+ result = await ocy.extract_text_async("https://example.com/code.png")
74
+ print(result["text"])
75
+
76
+ asyncio.run(main())
77
+ ```
78
+
79
+ ### 5. Use an API key
80
+
81
+ ```python
82
+ import ocy
83
+
84
+ # Option 1: Per-request key
85
+ result = ocy.extract_text("https://example.com/screenshot.png", api_key="your-key")
86
+
87
+ # Option 2: Set global key
88
+ ocy.set_api_key("your-key")
89
+ result = ocy.extract_text("https://example.com/screenshot.png")
90
+ ```
91
+
92
+ ## Response Format
93
+
94
+ ```python
95
+ {
96
+ "text": "extracted text from image...",
97
+ "confidence": 0.95, # 0.0 to 1.0
98
+ "latency_ms": 150, # processing time in milliseconds
99
+ "model": "ocy-v1-int8", # model identifier
100
+ "chars_detected": 42 # number of characters detected
101
+ }
102
+ ```
103
+
104
+ ## API Reference
105
+
106
+ | Function | Description |
107
+ |----------|-------------|
108
+ | `extract_text(img, api_key=None)` | Extract text synchronously |
109
+ | `extract_text_async(img, api_key=None)` | Extract text asynchronously |
110
+ | `set_api_url(url)` | Set custom API endpoint |
111
+ | `set_api_key(key)` | Set global API key |
112
+
113
+ ## License
114
+
115
+ MIT License - See [LICENSE](https://github.com/solez-ai/ocy/blob/main/LICENSE) for details.
@@ -0,0 +1,8 @@
1
+ README.md
2
+ pyproject.toml
3
+ ocy/__init__.py
4
+ ocy.egg-info/PKG-INFO
5
+ ocy.egg-info/SOURCES.txt
6
+ ocy.egg-info/dependency_links.txt
7
+ ocy.egg-info/requires.txt
8
+ ocy.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ httpx>=0.24.0
@@ -0,0 +1 @@
1
+ ocy
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ocy"
7
+ version = "1.0.0"
8
+ description = "Lightweight OCR for developer screenshots — extract text from code images, terminals, and IDE windows"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ authors = [
12
+ { name = "Samin Yeasar" }
13
+ ]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.8",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Topic :: Scientific/Engineering :: Image Recognition",
25
+ ]
26
+ dependencies = ["httpx>=0.24.0"]
27
+ requires-python = ">=3.8"
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/solez-ai/ocy"
31
+ Repository = "https://github.com/solez-ai/ocy"
32
+ Issues = "https://github.com/solez-ai/ocy/issues"
33
+
34
+ [tool.setuptools.packages.find]
35
+ where = ["."]
36
+ include = ["ocy*"]
ocy-1.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+