1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
URI Register - A high-performance PostgreSQL-backed URI to ID mapping service
This library provides a bidirectional mapping between URIs (strings) and integer IDs,
optimized for batch operations and designed for use in distributed systems.
Example (synchronous):
>>> from uri_register import UriRegister
>>>
>>> # Connect to PostgreSQL
>>> register = UriRegister(
... "postgres://localhost/mydb",
... "uri_register", # table_name
... 20, # max_connections
... 10000 # cache_size
... )
>>>
>>> # Register a single URI
>>> id = register.register_uri("http://example.org/resource/1")
>>> print(f"Registered with ID: {id}")
>>>
>>> # Register multiple URIs in batch (much faster!)
>>> uris = [
... "http://example.org/resource/2",
... "http://example.org/resource/3",
... ]
>>> ids = register.register_uri_batch(uris)
>>>
>>> # Get statistics
>>> stats = register.stats()
>>> print(f"Total URIs: {stats['total_uris']}")
Example (asynchronous):
>>> import asyncio
>>> from uri_register import UriRegister
>>>
>>> async def main():
... # Connect to PostgreSQL
... register = await UriRegister.new_async(
... "postgres://localhost/mydb",
... "uri_register", # table_name
... 20, # max_connections
... 10000 # cache_size
... )
...
... # Register a single URI
... id = await register.register_uri_async("http://example.org/resource/1")
... print(f"Registered with ID: {id}")
...
... # Register multiple URIs in batch (much faster!)
... uris = [
... "http://example.org/resource/2",
... "http://example.org/resource/3",
... ]
... ids = await register.register_uri_batch_async(uris)
...
... # Get statistics
... stats = await register.stats_async()
... print(f"Total URIs: {stats['total_uris']}")
>>>
>>> asyncio.run(main())
"""
=
=