# Sync and Async Clients

The official RegexSolver libraries send their requests through a client. Java and Python each ship a synchronous client and an asynchronous one; JavaScript ships a single client, and it is asynchronous. This page shows how to use each of them.

<CodeTabs defaultValue="java">
<CodeTabs.Tab value="java" label="Java">
In **Java**, you can choose between `RegexSolverClient` (synchronous) and `AsyncRegexSolverClient` (asynchronous).

**Synchronous**
```java
import com.regexsolver.api.RegexSolverClient;
import com.regexsolver.api.Term;
import com.regexsolver.api.exceptions.ApiException;

public class Main {
    public static void main(String[] args) throws ApiException {
        RegexSolverClient client = RegexSolverClient.builder()
            .apiToken(System.getenv("REGEXSOLVER_API_TOKEN"))
            .build();
        
        Term a = Term.regex("abc");
        Term b = Term.regex("def");
        
        Term result = client.union(a, b);
        System.out.println(result);
    }
}
```

**Asynchronous**
```java
import com.regexsolver.api.AsyncRegexSolverClient;
import com.regexsolver.api.Term;
import com.regexsolver.api.exceptions.ApiException;
import java.util.concurrent.CompletableFuture;

public class Main {
    public static void main(String[] args) throws ApiException {
        AsyncRegexSolverClient client = AsyncRegexSolverClient.builder()
            .apiToken(System.getenv("REGEXSOLVER_API_TOKEN"))
            .build();
        
        Term a = Term.regex("abc");
        Term b = Term.regex("def");
        
        // Returns a CompletableFuture<Term>
        client.union(a, b)
            .thenAccept(result -> System.out.println("Union: " + result));
    }
}
```
</CodeTabs.Tab>

<CodeTabs.Tab value="javascript" label="JavaScript">
In **JavaScript**, the library is **asynchronous-only**. All client methods are `async` and return a `Promise`.

```javascript
import { RegexSolverClient, Term } from 'regexsolver';

const client = new RegexSolverClient({
    apiToken: process.env.REGEXSOLVER_API_TOKEN
});

const a = Term.regex("abc");
const b = Term.regex("def");

// All methods return a Promise
const result = await client.union(a, b);
console.log(`Union: ${result}`);
```
</CodeTabs.Tab>

<CodeTabs.Tab value="python" label="Python">
In **Python**, you can use `RegexSolverClient` (synchronous) or `AsyncRegexSolverClient` (asynchronous using **`async/await`**).

**Synchronous**
```python
import os
from regexsolver import RegexSolverClient, Term

client = RegexSolverClient(api_token=os.getenv("REGEXSOLVER_API_TOKEN"))

a = Term.regex(r"abc")
b = Term.regex(r"def")

result = client.union(a, b)
print(f"Union: {result}")
```

**Asynchronous**
```python
import asyncio
import os
from regexsolver import AsyncRegexSolverClient, Term

async def main():
    async with AsyncRegexSolverClient(api_token=os.getenv("REGEXSOLVER_API_TOKEN")) as client:
        a = Term.regex(r"abc")
        b = Term.regex(r"def")

        # Non-blocking call
        result = await client.union(a, b)
        print(f"Union: {result}")

if __name__ == "__main__":
    asyncio.run(main())
```
</CodeTabs.Tab>
</CodeTabs>
